首页 > 其他 > 详细

加载properties配置文件

时间:2018-02-06 12:38:40      阅读:203      评论:0      收藏:0      [点我收藏+]

配置文件的路径为根路径:

//获取该配置文件的相对路径

String path = SysTemplate.class.getClassLoader().getResource("generator.properties").getPath();

File file = new File(path);
Properties pps = new Properties();
pps.load(new FileInputStream(file));
Enumeration enum1 = pps.propertyNames();//得到配置文件的名字
while(enum1.hasMoreElements()) {
String strKey = (String) enum1.nextElement();
String strValue = pps.getProperty(strKey);
System.out.println(strKey + "=" + strValue);
}

} catch (FileNotFoundException e) {
System.out.println("文件找不到異常");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

加载properties配置文件

原文:https://www.cnblogs.com/df1151112630/p/8421586.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!