Name
ZipOutputStream
Synopsis
This class is a subclass of
DeflaterOutputStream
that writes data in ZIP file
format to an output stream. Before writing any data to the
ZipOutputStream
, you must begin an entry within
the ZIP file with putNextEntry( )
. The
ZipEntry
object passed to this method should
specify at least a name for the entry. Once you have begun an entry
with putNextEntry( )
, you can write the contents
of that entry with the write( )
methods. When you
reach the end of an entry, you can begin a new one by calling
putNextEntry( )
again, you can close the current
entry with closeEntry( )
, or you can close the
stream itself with close( )
.
Before beginning an entry with
putNextEntry( )
, you can set the compression
method and level with setMethod( )
and
setLevel( )
. The constants
DEFLATED
and STORED
are the two
legal values for setMethod( )
. If you use
STORED
, the entry is stored in the ZIP file
without any compression. If you use DEFLATED
, you
can also specify the compression speed/strength tradeoff by passing a
number from 1 to 9 to setLevel( )
, where 9 gives
the strongest and slowest level of compression. You can also use the
constants Deflater.BEST_SPEED
,
Deflater.BEST_COMPRESSION
, and
Deflater.DEFAULT_COMPRESSION
with the
setLevel( )
method.
If you are storing an entry without compression, the ZIP file format
requires that you specify, in advance, the entry size and CRC-32
checksum in the ZipEntry
object for the entry. An exception is thrown if these values are not specified ...
Get Java in a Nutshell, 5th Edition 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.