我有一个从项目root读取配置文件但没有找到文件的类。
我的阅读课程在com.br.xxx.util package
中 String filename = "config.properties";
input = getClass().getResourceAsStream(filename);
此代码返回null,即使" config.properties"在我的项目根中。我在做什么错?
如果我使用:
InputStream input = new FileInputStream("C:\Users\xxxx\git\projectfolder\project\config.properties");
configFile.load(input);
它有效,但我不想使用系统路径。
config.properties必须在您的classpath
中。当您在Tomcat上部署项目时,默认情况下WEB-IN/classes
在classpath
中。最简单的解决方案是将config.properties
移至WEB-IN/classes
。