springboot项目打包后读取jar包里面的

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("模板不存在");
}

你可能感兴趣的:(spring,boot,jar,后端)