Java IO Tutorial - Java JarFile.getManifest()








Syntax

JarFile.getManifest() has the following syntax.

public Manifest getManifest()   throws IOException

Example

In the following code shows how to use JarFile.getManifest() method.

import java.util.Iterator;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
// ww w.j av a  2s  .c o m
public class Main {
  public static void main(String[] argv) throws Exception {
    JarFile jarfile = new JarFile("filename.jar");

    Manifest manifest = jarfile.getManifest();

    Map map = manifest.getEntries();

    for (Iterator it = map.keySet().iterator(); it.hasNext();) {
      String entryName = (String) it.next();

      Attributes attrs = (Attributes) map.get(entryName);

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

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