`
yuanlanjun
  • 浏览: 1185300 次
文章分类
社区版块
存档分类
最新评论

读取properties文件

 
阅读更多

记录工作中常用方法,方便以后使用


InputStream inputStream = MyClass.class.getClassLoader().getResourceAsStream("config.properties"); //还有另一种方法
Properties p = new Properties();
try {
    p.load(inputStream);
} catch (IOException e) {
    logger.error("配置文件config.properties载入出错", e);
    System.exit(-1);  //文件不存在
}
		
if((config = p.getProperty(Config_Name)) == null){
    logger.error("配置文件中 {} 字段不存在", Config_Name);
    System.exit(-1);
}

以下2个方法效果一样
PropertisUtil.class.getResourceAsStream("/config.properties");
PropertisUtil.class.getClassLoader().getResourceAsStream("config.properties");


以他方法参照

http://blog.csdn.net/senton/article/details/4083127

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics