property工具类

来源:互联网 发布:mirna数据库 编辑:程序博客网 时间:2024/06/16 16:38
public final class PropertiesInfoHelper {


    private static final Logger logger = LoggerFactory.getLogger(PropertiesInfoHelper.class);


private static ClassLoader classLoader = PropertiesInfoHelper.class.getClassLoader();


public final static Properties SYSCONFIG = readPropertiesFile("props/sysConfig.properties");
public final static Properties IDCONFIG = readPropertiesFile("props/idConfig.properties");


/**
* 在class路径下读取文件

* @param clazzPathFile
* @return
*/
private static Properties readPropertiesFile(String clazzPathFile) {
Properties properties = new Properties();
InputStreamReader is = null;


try {
is = new InputStreamReader(classLoader.getResourceAsStream(clazzPathFile), "UTF-8");
properties.load(is);
} catch (Exception e) {
            logger.error("Load properties file" + clazzPathFile + ", exception" + e.getMessage());
new RuntimeException("Load properties file" + clazzPathFile, e);
} finally {
if (is != null)
try {
is.close();
} catch (IOException e) {
                    logger.info("Close file exception, " + e.getMessage());
}
}


return properties;
}

}

使用:

PropertiesInfoHelper.IDCONFIG.getProperty("aaaal")

0 0