Steve Kuo
Steve Kuo

Reputation: 63134

Directory list of JAR file within classpath

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.

Upvotes: 1

Views: 7676

Answers (1)

Murali VP
Murali VP

Reputation: 6437

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.

Upvotes: 1

Related Questions