问题描述:spring项目打成jar包,启动时访问类路径下文件出错
问题代码:
FileInputStream is =new FileInputStream( (new ClassPathResource("fileName")).getFile() );
这里使用getFile方法会找不到文件
解决方式:
读取文件换成
InputStream is = new ClassPathResource("fileName").getInputStream();
再对流进行操作就可以了
问题描述:spring项目打成jar包,启动时访问类路径下文件出错
问题代码:
FileInputStream is =new FileInputStream( (new ClassPathResource("fileName")).getFile() );
这里使用getFile方法会找不到文件
解决方式:
读取文件换成
InputStream is = new ClassPathResource("fileName").getInputStream();
再对流进行操作就可以了