Java IO Tutorial - 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;
/* ww  w  .  ja v  a  2s. com*/
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);
  }
}