文件路径在 .jar (Spring) 中不起作用

本地一切正常,但是当我启动 jar 时,
我收到一个错误,提示它无法识别路径。
代码如下所示:

Path path = Paths.get(getclass().getclassLoader().getResource("classpath:images/" + image_title.getOriginalFilename()).toURI());
              
Files.copy(image_title.getInputStream(),path,StandardCopyOption.REPLACE_EXISTING);

错误:

2021-08-01 00:41:47.174 ERROR 13188 --- [nio-8080-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause

java.lang.NullPointerException: null
wyaizjj 回答:文件路径在 .jar (Spring) 中不起作用

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3780.html

大家都在问