Java IO Tutorial - Java JarFile(File file, boolean verify, int mode) Constructor








Syntax

JarFile(File file, boolean verify, int mode) constructor from JarFile has the following syntax.

public JarFile(File file,  boolean verify,  int mode)  throws IOException

Example

In the following code shows how to use JarFile.JarFile(File file, boolean verify, int mode) constructor.

//from w  w  w  .  j  av a  2s. c om
import java.io.File;
import java.util.Iterator;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

public class Main {
  public static void main(String[] argv) throws Exception {
    JarFile jarfile = new JarFile(new File("filename.jar"), true,JarFile.OPEN_READ);

    Manifest manifest = jarfile.getManifest();

    Attributes attrs = (Attributes) manifest.getMainAttributes();

    for (Iterator it = attrs.keySet().iterator(); it.hasNext();) {
      Attributes.Name attrName = (Attributes.Name) it.next();

      String attrValue = attrs.getValue(attrName);
    }
  }
}