- 1.问题描述
- 2.解决方案
今天分享一个发版遇到问题,读取resource下文件时报错,但是本地环境启动时并不会报错,最终定位到代码:
File jsonFile = ResourceUtils.getFile("classpath:xxx.json");
String settingJson = FileUtils.readFileToString(jsonFile, "UTF-8");
报错信息:
java.io.FileNotFoundException: class path resource [xxx] cannot be resolved to absolute file path because it does not reside in the file system: jar:file/xxx/BOOT-INF/classes/xxxxx
import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;
ClassPathResource classPathResource = new ClassPathResource("xxx.json");
String settingJson = IOUtils.toString(classPathResource.getInputStream(),"utf8");



