在main()
课堂上我放了一个代码:
App.getClass().getClassLoader().getResourceAsStream("Repo-Offer.properties")
结果是null
属性文件位于:
Project/src/main/resources/properties/Repo-Offer.properties
我试图加载这样的属性:
private Properties getPropertiesFromClasspath(String propFileName) throws IOException {
// loading xmlProfileGen.properties from the classpath
Properties props = new Properties();
InputStream inputStream = this.getClass().getClassLoader()
.getResourceAsStream(propFileName);
if (inputStream == null) {
throw new FileNotFoundException("property file '" + propFileName
+ "' not found in the classpath");
}
props.load(inputStream);
return props;
}
但由于那个 null 它说
Exception in thread "main" java.io.FileNotFoundException: Repo-Offer.properties
如何使用来自以下位置的属性文件:Project/src/main/resources/properties/Repo-Offer.properties,而源位于
Project/src/main/java/com/...
? 编辑这是 Maven 项目。