springboot 项目打成 jar 包后找不到 ResourceUtils.getFile 读取的文件

springboot 项目打成 jar 包后,找不到 ResourceUtils.getFile 读取的文件。使用 ResourceUtils.getFile 读取的文件为空

解决办法:
不使用 ResourceUtils.getFile 方法,改用 ClassPathResource 读取,具体代码如下

ClassPathResource classPathResource = new ClassPathResource("configfile/config.txt");
InputStream inputStream = classPathResource.getInputStream();

将读取的文件转成流,再对流进行操作

你可能感兴趣的:(spring,boot)