SpringBoot读取Resource下文件的几种方式


sPathResource classPathResource = new ClassPathResource("excleTemplate/test.xlsx");
InputStream inputStream =classPathResource.getInputStream();


第二种

File file = ResourceUtils.getFile("classpath:excleTemplate/test.xlsx");
InputStream inputStream = new FileInputStream(file);

 

------------------------------

读取resource/static/a.html文件的内容

ClassPathResource classPathResource=new ClassPathResource("static/a.html");
byte[] bytes= Files.readAllBytes(Paths.get(classPathResource.getAbsolutePath()));
String html=new String(bytes);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM