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);

 

posted @   甜菜波波  阅读(1569)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示