String classPath = ResourceUtils.CLASSPATH_URL_PREFIX + "mentor_template.xlsx"; File file = ResourceUtils.getFile(classPath); InputStream in = new FileInputStream(file); //读取excel模板 XSSFWorkbook wb = new XSSFWorkbook(in); XSSFSheet sheet = wb.getSheetAt(0); System.out.println(file == null);
注意:提示文件不存在時,查看編譯後的文件中是否存在要查找的文件,注意pom文件的配置
<profile>
<id>prod</id>
<build>
<resources>
<resource>
<directory>src/main/resources/prod</directory>
</resource>
<resource>
<directory>src/main/resources/base</directory>
</resource>
</resources>
</build>
</profile>