file path because it does not reside in the file system"/>
cannot be resolved to absolute file path because it does not reside in the file system
问题记录:java.io.FileNotFoundException: class path resource [temp/temp1.png] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/opt/secAuditServer/server/jhm-securelogin-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/temp/temp1.png
原因:spring cloud 项目打成JAR以后无法读取根路径和文件。
问题解决:
折中。读取不到文件,将文件流读入,再写入到临时路径下 ,然后再用完删除!
代码:
org.apachemons.io.FileUtils;
String path = Constants.IMPORT_TEMP_PATH + "/temp1.png";
Resource resource = new ClassPathResource("temp/temp1.png");
File file1 = new File(path);
FileUtils.copyToFile(resource.getInputStream(), file1);
记录以上!
更多推荐
cannot be resolved to absolute file path because it does not reside in the file
发布评论