1

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 =(

LeshaRB
  • 1,345
  • 2
  • 23
  • 44

2 Answers2

1

check PathMatchingResourcePatternResolver from io.micronaut.cli.io.support;

doodzio
  • 61
  • 4
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")
James Kleeh
  • 12,094
  • 5
  • 34
  • 61