读取资源文件ResourceUtils

第一种方法

File file = ResourceUtils.getFile("classpath:template/科研项目模板.xlsx");
//获取文件的相对路径 可在控制台打印查看输出结果
String filePath = ResourceUtils.getFile("classpath:template/科研项目模板.xlsx").getPath();



第二种方法

//直接将目标文件读成inputstream this指当前类的实例对象
InputStream ins = this.getClass().getClassLoader().getResourceAsStream("template/科研项目模板.xlsx");
File file = new File(ins);



目录结构如下

猜你喜欢

转载自www.cnblogs.com/cuiqq/p/12341238.html