1

The typically method to reference a file contained with a JAR file is to use ClassLoader.getResource. Is there a way to get the contents of a directory within a JAR files (similar to java.io.File.listFiles())? Note that the JAR file is within the classpath and its filename might not be known during runtime.

Basically I have a bunch of non-.class resource files within a directory. At runtime I need to load each resource file contained within a known directory.

Steve Kuo
  • 61,876
  • 75
  • 195
  • 257
  • possible duplicate of [How do I list the files inside a JAR file?](http://stackoverflow.com/questions/1429172/how-do-i-list-the-files-inside-a-jar-file) – Avinash R Oct 13 '14 at 08:06
  • See ["List files inside a JAR"](http://stackoverflow.com/questions/1429172/list-files-inside-a-jar/1429275#1429275). – erickson Nov 14 '09 at 00:35

1 Answers1

1

There is a system property called java.class.path, parse the path to your jar and then use JarURLConnection class to do what you want.

Murali VP
  • 6,198
  • 4
  • 28
  • 36