美文网首页
Java获取resources下的文件

Java获取resources下的文件

作者: 明月几何8 | 来源:发表于2020-12-07 10:15 被阅读0次

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

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

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

相关文章

网友评论

      本文标题:Java获取resources下的文件

      本文链接:https://www.haomeiwen.com/subject/aquzwktx.html