Java JarFile(File file) Constructor
Syntax
JarFile(File file) constructor from JarFile has the following syntax.
public JarFile(File file) throws IOException
Example
In the following code shows how to use JarFile.JarFile(File file) constructor.
import java.io.IOException;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.io.File;
/* w w w . j a v a 2 s. c o m*/
public class Main {
public static void main(String args[]) throws IOException {
JarFile jarFile = new JarFile(new File("c:/abc/yourJarFileName.jar"));
Enumeration<JarEntry> e = jarFile.entries();
while (e.hasMoreElements()) {
process(e.nextElement());
}
jarFile.close();
}
private static void process(Object obj) {
JarEntry entry = (JarEntry) obj;
String name = entry.getName();
long size = entry.getSize();
long compressedSize = entry.getCompressedSize();
System.out.println(name + "\t" + size + "\t" + compressedSize);
}
}