Get folder from Resources folder JAVA

Arnauld Alex picture Arnauld Alex · Apr 14, 2016 · Viewed 10.2k times · Source

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

Answer

Nicolas Filotto picture Nicolas Filotto · Apr 14, 2016

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

Your code is not even correct it should something like:

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