【发布时间】:2017-10-07 11:24:14
【问题描述】:
我正在尝试读取我的 Spring 引导控制台应用程序的资源文件夹中的文件,但我收到了 file not found 异常。
这是我的pom
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
这里是个例外:
java.io.FileNotFoundException: class path resource [9.txt] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/abc/Documents/workspace-sts-3.8.4.RELEASE/xyz/target/xyz-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/9.txt
我打开了 xyz-0.0.1-SNAPSHOT.jar 文件,9.txt 在 BOOT-INF/classes 文件夹中。
谢谢, -dj
【问题讨论】:
-
你读得怎么样?
-
我忘了提到我正在使用 ClassPathResource。 ClassPathResource 资源 = new ClassPathResource(len + ".txt");文件文件 = resource.getFile();
标签: spring-boot