【发布时间】:2018-10-14 18:43:33
【问题描述】:
我正在使用以下代码从类路径中读取文件:
Files.readAllBytes(new ClassPathResource("project.txt").getFile().toPath())
当 project.txt 在我的 WAR 的 src/main/resources 中时,这工作正常。现在我重构了代码并将某些代码移到了 JAR 中。这个新的 JAR 现在包括 src/main/resources/project.txt 和上面的代码。现在读取文件时出现以下异常:
java.io.FileNotFoundException: class path resource [project.txt]
cannot be resolved to absolute file path because it does
not reside in the file system:
jar:file:/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/viewer-1.0.0-SNAPSHOT.jar!/project.txt
我仍在 Tomcat 容器中执行 WAR。
我该如何解决这个问题?
【问题讨论】: