【发布时间】:2016-05-31 21:39:44
【问题描述】:
我在 src/test/java/com/pp/utils 中有一个 java 文件。我需要从此 Java 文件访问 src/test/resources 中的属性文件 example.properties。
我试过了:
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream("example.properties");
// load a properties file
prop.load(input);
// get the property value and print it out
System.out.println(prop.getProperty("key1"));
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
这会产生 FileNotFound 异常。路径应该是什么?或者我可以在哪里放置属性文件以便获取它?
【问题讨论】:
-
总是将资源作为流来访问您的属性文件
标签: java maven properties path filenotfoundexception