SpringBoot项目代码打包成jar文件,代码中如果需要读取resources目录下的文件,如下截图所示,例如:如果需要读取resources目录下test/test.txt文件。
java代码中可以采用类似下面的方式读取:
import org.springframework.core.io.ClassPathResource;
ClassPathResource classPathResource = new ClassPathResource( " test / test.txt " );
String str = IOUtils.toString(classPathResource.getInputStream(),
"UTF-8" );