Close

List all files in a classpath resource folder

[Last Updated: Dec 7, 2016]

Java 

public class Test{

private static File[] getResourceFolderFiles (String folder) {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
URL url = loader.getResource(folder);
String path = url.getPath();
return new File(path).listFiles();
}

public static void main (String[] args) {
for (File f : getResourceFolderFiles("aFolderInClassPath")) {
System.out.println(f);
}
}
}


See Also