因打包为jar之后,要使用jar里面的文件,使用的是虚拟路径,可能会报错
Caused by: java.io.FileNotFoundException: class path resource [***.***] cannot be resolved to absolute
.***.jar/BOOT-INF/classes!/***.**
,解决办法就是先把要使用的文件读写为流,然后生成自己所需要的文件。
比如:
//在根目录生成一个文件 File targetFile = new File("\\hk.json"); InputStream inputStream=this.getClass().getResourceAsStream("/static/hk.json"); //将流转成File格式 FileUtils.copyInputStreamToFile(inputStream, targetFile);