Java™ Platform
Standard Ed. 8
compact1, compact2, compact3
java.util.zip
Class ZipOutputStream
-
-
Method Summary
All Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
void |
close() |
Closes the ZIP output stream as well as the stream being filtered.
|
void |
closeEntry() |
Closes the current ZIP entry and positions the stream for writing
the next entry.
|
void |
finish() |
Finishes writing the contents of the ZIP output stream without closing
the underlying stream.
|
void |
putNextEntry(ZipEntry e) |
Begins writing a new ZIP file entry and positions the stream to the
start of the entry data.
|
void |
setComment(String comment) |
Sets the ZIP file comment.
|
void |
setLevel(int level) |
Sets the compression level for subsequent entries which are DEFLATED.
|
void |
setMethod(int method) |
Sets the default compression method for subsequent entries.
|
void |
write(byte[] b,
int off,
int len) |
Writes an array of bytes to the current ZIP entry data.
|
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
setMethod
public void setMethod(int method)
Sets the default compression method for subsequent entries. This
default will be used whenever the compression method is not specified
for an individual ZIP file entry, and is initially set to DEFLATED.
- Parameters:
method - the default compression method
- Throws:
IllegalArgumentException - if the specified compression method
is invalid
-
putNextEntry
public void putNextEntry(ZipEntry e)
throws IOException
Begins writing a new ZIP file entry and positions the stream to the
start of the entry data. Closes the current entry if still active.
The default compression method will be used if no compression method
was specified for the entry, and the current time will be used if
the entry has no set modification time.
- Parameters:
e - the ZIP entry to be written
- Throws:
ZipException - if a ZIP format error has occurred
IOException - if an I/O error has occurred
-
write
public void write(byte[] b,
int off,
int len)
throws IOException
Writes an array of bytes to the current ZIP entry data. This method
will block until all the bytes are written.
- Overrides:
write in class DeflaterOutputStream
- Parameters:
b - the data to be written
off - the start offset in the data
len - the number of bytes that are written
- Throws:
ZipException - if a ZIP file error has occurred
IOException - if an I/O error has occurred
- See Also:
FilterOutputStream.write(int)
-
finish
public void finish()
throws IOException
Finishes writing the contents of the ZIP output stream without closing
the underlying stream. Use this method when applying multiple filters
in succession to the same output stream.
- Overrides:
finish in class DeflaterOutputStream
- Throws:
ZipException - if a ZIP file error has occurred
IOException - if an I/O exception has occurred
Java™ Platform
Standard Ed. 8
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.