我已经创建了一个属性文件,并试图在我的Spring DAO类文件中访问它,但我得到了 "java.io.FileNotFoundException: config.properties (The system cannot find the file specified)" . 我尝试过不同的方案将文件放在不同的文件夹/位置但遇到同样的问题 . 任何人都可以帮我这个 . 以下是代码和结构细节,
在DAO班,
FileReader reader = new FileReader("config.properties");
Properties properties = new Properties();
properties.load(reader);
我试图将"config.properties"文件放在 src/main/resources 下,也放在 WEB-INF/
下 . 我的DAO课程在 src/main/java/com/test/dao
谢谢你 .
1 回答
您可以将文件保存在最合适的src / main / resources中,并将其检索方式更改为: