Close

List all files in a classpath resource folder

[Updated: Dec 7, 2016, Created: Feb 13, 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