您的位置:首页 > 编程语言 > Java开发

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

2015-03-21 12:26 661 查看

文件存储路径的问题

错误描述 :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");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐