How can I get the path of a JarEnrty?

Alessandro A. Garbagnati

java.util.jar.JarEntry is a subclass of java.util.zip.ZipEntry. If you use the getName() method on your JarEntry object, you will get the full name of the entry, including its path (relative or absolute depending on how it was created). If the entru is a directory, the isDirectory() method will return true.

Try this piece of code:

...
JarFile file = new JarFile(<path of a jar file>);
for (Enumeration enum=file.entries(); enum.hasMoreElements();) {
  JarEntry entry = (JarEntry)enum.nextElement();
  System.out.println("Name = " + entry.getName());
  System.out.println("is directory = " + entry.isDirectory());
  System.out.println();
}
file.close();
Remember to add some try/catch blocks... ;-)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.