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 @ 2021-06-04 17:40  甜菜波波  阅读(1553)  评论(0编辑  收藏  举报