Spring Boot 获取 resource 目录下的文件
Spring Boot Java About 408 wordsResourceUtils
虽然Spring
提供的工具类ResourceUtils
在Windows
上可以正常使用,但这个工具类在CentOS
上可能会遇到读取不到文件的问题。
File file = ResourceUtils.getFile("classpath:application.yml")
ClassPathResource
使用ClassPathResource
可以正常获取。注意一点就是:除配置文件外的其他文件,应建立文件夹后,放入文件夹。
ClassPathResource classPathResource = new ClassPathResource("pic/test.png");
InputStream inputStream = classPathResource.getInputStream();
File file = classPathResource.getFile();
Views: 3,944 · Posted: 2020-05-22
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓

Loading...