三种方式
一、
ClassPathResource classPathResource = new ClassPathResource("file/template/cpsp_check_account.xlsx");
InputStream inputStream = classPathResource.getInputStream();
二、
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("file/template/cpsp_check_account.xlsx");
三、
InputStream inputStream = this.getClass().getResourceAsStream("/file/template/cpsp_check_account.xlsx");
pom文件中设置
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xlsx</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.yml</include>
<include>**/Dockerfile</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xlsx</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.yml</include>
<include>**/Dockerfile</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
转载:https://www.cnblogs.com/chenzhoulibo/p/10735910.html