In spring I can use ResourceLoader and 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);
}
}
and use it
Resource[] resources = foobar.loadResources("classpath*:../../dir/*.txt");
How I can do it in Micronaut?
I find one solution Is there an equivalent for Springs Resource in Micronaut?
ADD
@Inject
private DefaultClassPathResourceLoader resourceLoader;
...
Stream<URL> currencyStream = resourceLoader.getResources("currency/*.json");
long count = currencyStream.count();
...
But count always 0 =(
There is no equivalent of the Resource
interface, however you can retrieve resources in URL format.
Inject a io.micronaut.context.env.ResourceLoader
. It has Stream<URL> getResources(String name)
EDIT: An example
resourceLoader.getResources("some/directory/test.txt")