解决在spring boot打成jar包后读取resource下资源文件抛出 java.io.FileNotFoundException
具体报错如下:file:/data/XXX/xxxx.jar.!/BOOT-INF/classes!/configs/xxxxx.xlsx(No such file or directory),
开发环境spring boot2.15
需求:在resource下需要提供一套excel,world格式供前端下载模板
String file = "static/人员基础信息导入模板.xlsx";
BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file));
OutputStream outputStream = response.getOutputStream();
这种读取方式只能在本地运行项目的时候使用,一旦发布项目(打包成jar)在调用这个接口时候会出现file:/data/XXX/xxxx.jar.!/BOOT-INF/classes!/configs/xxxxx.xlsx(No such file or directory);异常
完整代码可以直接使用
@GetMapping("/personnel/downloadTemplate")
public void downloadLocal(HttpServletResponse response) throws IOException {
/** 获取静态文件的路径 */
String pa