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);
原文地址:https://www.cnblogs.com/tiancai/p/14850601.html