日常小结-spring中读取resources下的资源文件

120 阅读1分钟

spring中读取resources下的资源文件

问题描述:当使用

File file = new File("filePath");

这种在idea中是可以运行,但是打包到tomcat中就不行了,因为我们写的路径是本地电脑上的文件路径

解决方案:

Properties properties = new Properties();
ClassPathResource classPathResource = new ClassPathResource("application.properties");
properties.load(classPathResource.getInputStream());