Listing the files that are contained in a Jar file

Main.java:

import java.io.*;
import java.util.*;
import java.util.jar.*;
 
public class Main
{
   public static void main(String[] args) throws IOException 
   {
      if (args.length != 1) {
         System.out.println("Usage: java Main <file.jar>");
         System.exit(1);
      }
 
      listContents(args[0]);
   }
 
   public static void listContents(String jarfilename) throws IOException {
      JarFile jar = new JarFile(jarfilename);
 
      for (Enumeration e=jar.entries(); e.hasMoreElements(); ) {
         JarEntry je = (JarEntry) e.nextElement();
         System.out.println(je.getName());
      }
   }
}

outputs for jmxgrinder.jar:

META-INF/
META-INF/MANIFEST.MF
Introspector.class
IntrospectionException.class
JMException.class
JMRuntimeException.class
GrinderWrapper.class
MBeanAttributeInfo.class
MBeanConstructorInfo.class
MBeanInfo.class
MBeanFeatureInfo.class
MBeanNotificationInfo.class
MBeanOperationInfo.class
MBeanParameterInfo.class
MetaData.class
NotCompliantMBeanException.class
OperationsException.class
RuntimeErrorException.class
resources/JMX.properties
resources/unresolvedMBean.gif
resources/standardMBean.gif
resources/dynamicMBean.gif
resources/noncompliantMBean.gif
resources/check.gif
resources/load.gif
JMXResult.class
JMXResources.class
...