Java 找不到Maven属性文件
我正在使用maven web应用程序。 以下是我放置属性文件的项目结构。Java 找不到Maven属性文件,java,maven,Java,Maven,我正在使用maven web应用程序。 以下是我放置属性文件的项目结构。 以下是我用来读取此文件的代码: public static Properties loadProducerProperty() throws FileException { Properties myProperties = new Properties(); try { String resourceName = "newproperties.properties"; // co
以下是我用来读取此文件的代码:
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
异常
我已经通过以下链接并尝试了其他方法,但我得到了相同的错误:
我在这里做错了什么
谢谢在文件名前添加斜杠:
String resourceName = "/newproperties.properties"; // could also be a constant