Java JarFile(String name) Constructor

Syntax

JarFile(String name) constructor from JarFile has the following syntax.

public JarFile(String name)  throws IOException

Example

In the following code shows how to use JarFile.JarFile(String name) constructor.


import java.io.IOException;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
//from  w  w w . j  a  v a  2s. c  om
public class Main {
  public static void main(String args[]) throws IOException {

    JarFile jarFile = new JarFile("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);
  }
}




















Home »
  Java Tutorial »
    java.util.jar »




JarFile
Pack200