【发布时间】:2016-12-08 23:22:06
【问题描述】:
我正在使用 Maven 网络应用程序。
以下是我放置属性文件的项目结构。
以下是我用来读取此文件的代码:
public static Properties loadProducerProperty() throws FileException {
Properties myProperties = new Properties();
try {
String resourceName = "newproperties.properties"; // could also be a constant
ClassLoader loader = Thread.currentThread().getContextClassLoader();
try (InputStream resourceStream = loader.getResourceAsStream(resourceName)) {
myProperties.load(resourceStream);
}
} catch (FileNotFoundException e) {
throw new FileException();
} catch (IOException e) {
throw new FileException();
}
return myProperties;
}
但我收到了FileNotFound 异常
我已经浏览了以下链接并尝试了其他方法,但我遇到了同样的错误:
Cannot load properties file from resources directory
我在这里做错了什么。
谢谢
【问题讨论】: