目标:
1、获取resource目录某个文件夹下所有文件信息
2、jar可执行
网上大多数都是只能获取一个文件,或者jar不可执行
解决方式:
直接上代码:
public static void load(String locationPattern) throws IOException {
Resource[] resources = new PathMatchingResourcePatternResolver().getResources(locationPattern);
for (Resource resource : resources) {
String filename = resource.getFilename();
InputStream inputStream = resource.getInputStream();
File file = FileLoadCopyUtil.fileCopy(inputStream, filename);
log.info("dlllaod:" + file.getName());
}
}
核心代码:
Resource[] resources = new PathMatchingResourcePatternResolver().getResources(locationPattern);
注意:操作的时候要使用文件流,不要通过路径来操作获取的结果,应为jar包中文件路径不标准。