O'Reilly logo

Java I/O by Elliotte Rusty Harold

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

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

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