Printing the contents of the manifest file found in a jar?

Question:
How to print the contents of the manifest file found in a jar?

Code:
import java.io.*;
import java.util.*;
import java.util.jar.*;
 
public class PrintManifest {
  public static void main(String[] args) {
    try {
      JarFile jarfile = new JarFile("/jdk1.8.0_40/jre/lib/rt.jar");
      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);
        System.out.println(attrName + ": " + attrValue);
      }
 
    } catch (Exception e) {
      System.out.println("There was a problem....");
    }
  }
}

Output:
$ java PrintManifest
Implementation-Vendor: Oracle Corporation
Implementation-Title: Java Runtime Environment
Implementation-Version: 1.8.0_40
Specification-Vendor: Oracle Corporation
Manifest-Version: 1.0
Specification-Title: Java Platform API Specification
Created-By: 1.7.0_07 (Oracle Corporation)
Specification-Version: 1.8