`

properties 文件操作

阅读更多
*/
public static String getConfigurationInfoByKey(String key) {
// 获取存在外部配置文件的文件路径
String strConfPath = System.getenv().get(Constant.CONF_PATH);
InputStream in = null;
// 用于存储配置信息的value
String strConfigurationInfoValue = "";
try {
in = new FileInputStream(new File(strConfPath + "/" + Constant.CONF_FILE_NAME));
Properties properties = new Properties();
// 加载配置信息资料文件
properties.load(in);

// 根据配置信息的key获取对应的value
strConfigurationInfoValue = properties.getProperty(key);

} catch (FileNotFoundException e) {
logger.error("获取资源文件出错:",e);
e.printStackTrace();
} catch (IOException e) {
logger.error("加载资源文件到输出流出错:",e);
e.printStackTrace();
} finally {
            try {
                if(in != null){
                    in.close();
                }
            } catch (IOException e) {
            logger.error("IOException: ", e);
            }
        }
        return strConfigurationInfoValue.trim();
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics