How can I read .zip and .jar file using standard Java classes?
Location: http://www.jguru.com/faq/view.jsp?EID=41035 Created: Apr 27, 2000 Modified: 2001-08-18 17:12:00.941 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Question originally posed by Khoivu N (http://www.jguru.com/guru/viewbio.jsp?EID=32600 The ZIP and JAR reading classes are found in the java.util.zip and java.util.jar packages respectively. The following demonstrates reading from a ZIP file, listing all the files in the zip and displaying the contents of the first file in the zip. JAR file reading is similar, just with different classes and having a manifest. import java.util.zip.*; import java.util.*; import java.io.*; public class ZipExample { public static void main(String args[]) { try { ZipFile zf = new ZipFile(“the.zip”); Enumeration entries = zf.entries(); String first = null; while (entries.hasMoreElements()) { ZipEntry ze = (ZipEntry)entries.nextElement(); System.out.println(“Entry ” + ze.getName()); if (first == null) first = ze.getName(); } ZipEntry
Location: http://www.jguru.com/faq/view.jsp?EID=41035 Created: Apr 27, 2000 Modified: 2001-08-18 17:12:00.941 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Question originally posed by Khoivu N (http://www.jguru.com/guru/viewbio.jsp?EID=32600 The ZIP and JAR reading classes are found in the java.util.zip and java.util.jar packages respectively. The following demonstrates reading from a ZIP file, listing all the files in the zip and displaying the contents of the first file in the zip. JAR file reading is similar, just with different classes and having a manifest.