解决springboot读取jar包中文件的问题 ╰半橙微兮° 2022-05-31 23:26 194阅读 0赞 在开发环境中,使用 ResourceUtils.getFile(“classpath:static/files/8k.wav”) 能读取到 File ,结果打包发布后,读取不了。 解决方法 InputStream stream = getClass().getClassLoader().getResourceAsStream("static/files/8k.wav"); File targetFile = new File("files/8k.wav"); FileUtils.copyInputStreamToFile(stream, targetFile); 或通过以下方式获取 ClassPathResource resource = new ClassPathResource("static/office_template/word_replace_tpl.docx"); File sourceFile = resource.getFile(); InputStream fis = resource.getInputStream(); ###### 还可以参考此篇文章中的方法:[https://blog.csdn.net/zhuyu19911016520/article/details/98071242][https_blog.csdn.net_zhuyu19911016520_article_details_98071242] ###### [https_blog.csdn.net_zhuyu19911016520_article_details_98071242]: https://blog.csdn.net/zhuyu19911016520/article/details/98071242
还没有评论,来说两句吧...