javafilesrc

Get folder from Resources folder JAVA


Hi everyone I can't figure out with this problem : this line of code should work

File[] file = (new File(getClass().getResource("resources/images_resultats"))).listFiles();

I want a list of File, these Files are under "images_resultats" under "resources".

Project image


Solution

  • It won't work if resources/images_resultats is not in your classpath and/or if it is in a jar file.

    Your code should rather be something like this:

    File[] file = (new File(getClass().getResource("/my/path").toURI()))
                      .listFiles();