`

读取属性配置文件

    博客分类:
  • Java
阅读更多

 

InputStream inStream= ClassLoader.getSystemClassLoader().getResourceAsStream("config.properties");
Properties prop=new Properties();
prop.load(inStream);
String cfged=prop.getProperty(cfg);
 


以上ClassLoader.getSystemClassLoader().getResourceAsStream表示,读取文件的动作会到classpath路径;

在eclipse中,就是src下,因为eclipse会把src目录下的文件编译到classpath路径之下。

所以配置文件config.properties必须放到src之下。

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics