O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading a JAR or Zip Archive

// reading a zip file
											ZipFile file = new ZipFile(filename);
											Enumeration entries = file.entries();
											while (entries.hasMoreElements()) {
											ZipEntry entry =
											(ZipEntry)entries.nextElement();
											if (entry.isDirectory()) {
											// process directory
											}
											else {
											// process file
											}
											}
											file.close();

Java has built-in support for reading and writing Zip archive files. A JAR file is a Zip file that contains specified content, so you can also use the Zip file classes and methods to read a JAR file. The zip classes are contained in the java.util.zip package, which is part of the standard JDK. In this phrase, we first create a ZipFile object by passing the filename of an existing Zip file to the constructor of the ZipFile class. We then get all ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required