1

Suppose I've got a few resource files in my classpath:

/a/b/c/x1.txt
/a/b/d/x2.txt
/a/b/e/x3.txt

My code does not know the full paths of these resource files. It knows only their extension .txt.
How would you write a function to return the paths of the resources with extension .txt ?

Michael
  • 41,026
  • 70
  • 193
  • 341

1 Answers1

2

Try this:

Path path = Paths.get(YourClass.class.getResource("/resources").toURI());

List<String> result = Files.find(path, 100,
        (p, a) -> p.toString().toLowerCase().endsWith(".txt"))
        .map(Path::toString)
        .collect(Collectors.toList());
Lungu Daniel
  • 816
  • 2
  • 8
  • 15