This question is in reference with another stackoverflow post - How to load all files of a folder to a list of Resources in Spring?
I want to load all files from two specific folders using ResourceLoader. I am trying to use ResourcePatternUtils.
class Foobar { private ResourceLoader resourceLoader;
@Autowired
public Foobar(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
Resource[] loadResources(String pattern) throws IOException {
return ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources(pattern);
}
}
Resource[] resources1 = foobar.loadResources("classpath*:../../folder1/*.txt");
Resource[] resources2 = foobar.loadResources("classpath*:../../folder2/*.txt");
But I need both the resources in a single array. Should I be using something like Java8 stream to concatenate them ?