java项目打包部署后文件路径修改

https://www.jb51.net/article/215619.htm

 

在本地项目读取文件时

this.getClass().getClassLoader().getResource("").getPath()+fileName
this.getClass().getResource("/filename").getPath()

 

SpringBoot项目打包成jar后获取classpath下文件失败

解决方案

ClassPathResource resource = new ClassPathResource("\\static\\pattern\\test.txt"); // static/pattern下的 test.txt文件
InputStream in = resource.getInputStream(); //获取文件输入流

posted @ 2022-08-18 10:28  ZikC  阅读(323)  评论(0编辑  收藏  举报