KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ZipList


1 // ZipList.java
2

3
4 import java.io.*; // for File I/O Classes
5
import java.util.*; // for Vector/Hashtable
6
import java.util.zip.*; // for ZipInputStream/ZipEntry classes
7

8
9 public class ZipList {
10
11     public static void main( String JavaDoc [] args )
12     {
13     if (args.length != 1 ) {
14         System.out.println( "USAGE: java ZipList <ZIPFILE/JARFILE>" );
15         System.exit(1);
16     }
17     
18     try {
19         System.out.println( "Zip list entry of file:`"+args[0]+"'");
20         FileInputStream fis = new FileInputStream( args[0] );
21         ZipInputStream zis = new ZipInputStream( fis );
22         
23         ZipEntry zipEntry;
24         int total=0;
25         
26
27         do {
28         zipEntry = zis.getNextEntry();
29         if (zipEntry != null ) {
30             ++total;
31             int method = zipEntry.getMethod();
32             System.out.println( "*** ENTRY ["+total+"] ***" );
33             System.out.println( "name: " + zipEntry.getName() );
34             System.out.println( "size: " + zipEntry.getSize() );
35             System.out.println( "extra: " + zipEntry.getExtra() );
36             System.out.println( "compressed size: " + zipEntry.getCompressedSize() );
37             System.out.println( "method: " +
38                     (method == ZipEntry.DEFLATED ? "(Compressed)" :
39                      method == ZipEntry.STORED ? "(Stored)" : "PASS!" ));
40             zis.closeEntry();
41         }
42         }
43         while (zipEntry != null);
44
45         zis.close();
46     }
47     catch (IOException e) {
48         System.err.println(e);
49     }
50     }
51 }
52
53 // fini
54
Popular Tags