ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resourcePatternResolver.getResources("classpath*:templates/*.*");
for ( Resource resource : resources ) {
//获取文件,在打成jar包后,通过url来获取文件,则路径是正确的
File file = new File(resource.getURL().getFile());
System.out.println(file.getName());
}
//读取要下载的文件,保存到文件输入流
InputStream inputStream = resourcePatternResolver.getResource(templatePath).getInputStream();
if (ObjectUtil.isEmpty(inputStream)) {
throw new RuntimeException("模板不存在");
}
springboot项目打包后读取jar包里面的
最新推荐文章于 2024-08-26 03:01:55 发布