// File: IO23.java (Module 13) // // Author: Rahul Simha // Created: Nov 28, 1998 // // Reading from a JAR file. import java.io.*; import java.util.zip.*; import java.util.*; public class IO23 { public static void main (String[] argv) { try { // First open the ZIP file. ZipFile zipFile = new ZipFile ("blah.jar"); // Get an Enumeration of its contents. Enumeration e = zipFile.entries (); int count = 1; // Process one by one. while (e.hasMoreElements()) { // Get an element. ZipEntry zipEntry = (ZipEntry) e.nextElement(); // Get an input stream attached to the entry. InputStream inStream = zipFile.getInputStream(zipEntry); // Wrap high-level reader around the input stream. InputStreamReader osr = new InputStreamReader (inStream); LineNumberReader lnr = new LineNumberReader (osr); System.out.println ("ZIP ENTRY #" + count + ": " + zipEntry); // Read. String s = lnr.readLine (); while (s != null) { System.out.println (s); s = lnr.readLine (); } lnr.close (); count++; // Repeat. } } catch (IOException e) { System.out.println (e); } } }