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 ...

Get Java™ Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.