cannot be resolved to absolute file path because it does not reside in the file system

编程入门 行业动态 更新时间:2024-10-28 03:20:46

cannot be resolved to absolute <a href=https://www.elefans.com/category/jswz/34/1770945.html style=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

本文发布于:2024-02-24 18:16:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1696242.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:file   absolute   resolved   system   reside

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!