Working with Zip Files
Gzip and deflate are compression formats. Zip is both a compression and an archive format. This means that a single zip file may contain more than one uncompressed file, along with information about the names, permissions, creation and modification dates, and other information about each file in the archive. This makes reading and writing zip archives somewhat more complex and somewhat less amenable to a stream metaphor than reading and writing deflated or gzipped files.
The java.util.zip.ZipFile
class represents a file
in the zip format. Such a file might be created by zip, PKZip, ZipIt,
WinZip, or any of the many other zip programs. The
java.util.zip.ZipEntry
class represents a single
file stored in such an archive.
public class ZipFile extends Object implements ZipConstants public class ZipEntry extends Object implements ZipConstants
Note
The
java.util.zip.ZipConstants
interface that both these classes
implement is a rare nonpublic interface that contains constants
useful for reading and writing zip files. Most of these constants
define the positions in a zip file where particular information, like
the compression method used, is found. You don’t need to
concern yourself with it.
The ZipFile
class contains two constructors. The
first takes a filename as an argument. The second takes a
java.io.File
object as an argument.
File
objects will be discussed in Chapter 12 ; for now, I’ll just use the constructor that accepts a filename. Functionally, these two constructors ...
Get Java I/O 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.