ZipTest.java
import java.io.*;
import java.util.zip.*;
/**
Dump a listing of the files in a set of ZIP archives to standard out.
*/
class ZipTest
{
public static void main(String[] argv)
{
for (int i=0; i<argv.length; i++)
listZip(argv[i]);
}
public static void listZip(String name)
{
ZipEntry zentry;
try {
File zfile = new File(name);
if (zfile.exists() && zfile.canRead()) {
System.out.println(
"\n\n========== ZIP archive '" + name + "':");
ZipInputStream z =
new ZipInputStream(new FileInputStream(zfile));
while ((zentry=z.getNextEntry()) != null) {
System.out.println("\n\n========== " +
zentry.getName());
BufferedReader br =
new BufferedReader(
new InputStreamReader(z));
String line;
while ((line=br.readLine()) != null)
System.out.println(line);
z.closeEntry();
}
z.close();
}
else {
System.out.println(
"File '" + name + "' does not exist!");
}
}
catch (IOException e) {
System.out.println("IOException: " + e);
}
}
}