Java获取resources下的文件

2020-12-07  本文已影响0人  明月几何8

今天做项目遇到一个需求,需要从后端获取导入的模板文件,通过File file = new File("")获取文件失败,即使获取到了,当程序打成jar包时也会出现问题。
解决方案:

ClassPathResource classPathResource = new ClassPathResource("filePath");
InputStream inputStream = classPathResource.getInputStream();

参考链接:https://blog.csdn.net/wohaqiyi/article/details/80147999

上一篇 下一篇

猜你喜欢

热点阅读