I have this code which reads all the files from a directory.
File textFolder = new File(\"text_directory\");
File [] texFiles = textFolder.listFiles
Given an actual JAR file, you can list the contents using JarFile.entries()
. You will need to know the location of the JAR file though - you can't just ask the classloader to list everything it could get at.
You should be able to work out the location of the JAR file based on the URL returned from ThisClassName.class.getResource("ThisClassName.class")
, but it may be a tiny bit fiddly.