I'm building a system that allows users to upload files to LibGDX's local directory to play them in the game. How can I search recursively through the local file system for a specific file type and return all returned files?


1 Answer 1


You could use Files.walk() along with filter(). Thus if you wanted to get all PNG images, then you could do:

Path path = Paths.get(Gdx.files.getLocalStoragePath());

try {
    List<Path> files = Files.walk(path)
        .filter(filePath -> !Files.isDirectory(filePath) && 
catch (IOException ex) {

The example starts searching from Gdx.files.getLocalStoragePath() continuously searching all subdirectories for any file ending with .png.

It might be important to include !Files.isDirectory(filePath) as technically someone could name a directory test.png.

  • \$\begingroup\$ I get this error: Usage of API Document @ 1.7 This inspection finds all usages of methods that have @since in their documentation. This may be useful for development for development under newer SDKs \$\endgroup\$ Commented Apr 1, 2017 at 19:35
  • 1
    \$\begingroup\$ It's telling your that it knows what it is, but that it comes from 1.7. Sounds like you're not using at least 1.7. \$\endgroup\$
    – vallentin
    Commented Apr 1, 2017 at 19:41
  • \$\begingroup\$ Does that mean that I need to update java itself or in android studio? \$\endgroup\$ Commented Apr 1, 2017 at 19:43
  • \$\begingroup\$ You just need to change the language level. Whether you need to update anything depends on what you currently have. \$\endgroup\$
    – vallentin
    Commented Apr 1, 2017 at 19:45
  • \$\begingroup\$ I've updated it to jdk1.8.0_111 and it still gives errors. \$\endgroup\$ Commented Apr 1, 2017 at 20:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .