Spring Boot 获取 resource 目录下的文件

Spring Boot Java About 408 words

ResourceUtils

虽然Spring提供的工具类ResourceUtilsWindows上可以正常使用,但这个工具类在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,542 · Posted: 2020-05-22

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓
Today On History
Browsing Refresh