Java properties | FileNotFoundException: properties (系统找不到指定的文件。)

文件存储路径的问题

 

错误描述 :FileNotFoundException: init.properties (系统找不到指定的文件。)

 

1.方法一
InputStream fis =TestProperties.class.getClassLoader().getResourceAsStream("init.properties")

2.方法二(要求TestProperties和init.properties在同一目录下)
InputStream fis =TestProperties.class搜索.getResourceAsStream("init.properties")

 

推荐使用2。 放在TestProperties.java同级目录下面

3.方法三,对于Web工程也可以这样。
先获取ServletContext,然后
InputStream in=context.getResourceAsStream("/WEB-INF/classes/init.properties");

 

posted @ 2015-03-21 12:26  一杯半盏  阅读(594)  评论(0编辑  收藏  举报