ZipFile
open class ZipFile : Closeable
| kotlin.Any | |
| ↳ | java.util.zip.ZipFile |
This class is used to read entries from a zip file.
Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.
Summary
| Constants | |
|---|---|
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Long | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Long | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Long | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Long | |
| static Int | |
| static Int | |
| static Int | |
| static Int |
Mode flag to open a zip file and mark it for deletion. |
| static Int |
Mode flag to open a zip file for reading. |
| Public constructors | |
|---|---|
|
Opens a zip file for reading. |
|
|
Opens a new |
|
|
Opens a ZIP file for reading given the specified File object. |
|
|
Opens a new |
|
|
Opens a zip file for reading. |
|
|
Opens a ZIP file for reading given the specified File object. |
|
| Public methods | |
|---|---|
| open Unit |
close()Closes the ZIP file. |
| open Enumeration<out ZipEntry!>! |
entries()Returns an enumeration of the ZIP file entries. |
| open String! |
Returns the zip file comment, or null if none. |
| open ZipEntry! |
Returns the zip file entry for the specified name, or null if not found. |
| open InputStream! |
getInputStream(entry: ZipEntry!)Returns an input stream for reading the contents of the specified zip file entry. |
| open String! |
getName()Returns the path name of the ZIP file. |
| open Int |
size()Returns the number of entries in the ZIP file. |
| open Stream<out ZipEntry!>! |
stream()Return an ordered |
| Protected methods | |
|---|---|
| open Unit |
finalize()Ensures that the system resources held by this ZipFile object are released when there are no more references to it. |
Constants
OPEN_DELETE
static val OPEN_DELETE: Int
Mode flag to open a zip file and mark it for deletion. The file will be deleted some time between the moment that it is opened and the moment that it is closed, but its contents will remain accessible via the ZipFile object until either the close method is invoked or the virtual machine exits.
Value: 4
OPEN_READ
static val OPEN_READ: Int
Mode flag to open a zip file for reading.
Value: 1
Public constructors
ZipFile
ZipFile(name: String!)
Opens a zip file for reading.
First, if there is a security manager, its checkRead method is called with the name argument as its argument to ensure the read is allowed.
The UTF-8 charset is used to decode the entry names and comments.
| Parameters | |
|---|---|
name |
String!: the name of the zip file |
| Exceptions | |
|---|---|
java.util.zip.ZipException |
if a ZIP format error has occurred |
java.io.IOException |
if an I/O error has occurred |
java.lang.SecurityException |
if a security manager exists and its checkRead method doesn't allow read access to the file. |
ZipFile
ZipFile(
file: File!,
mode: Int)
Opens a new ZipFile to read from the specified File object in the specified mode. The mode argument must be either OPEN_READ or OPEN_READ | OPEN_DELETE.
First, if there is a security manager, its checkRead method is called with the name argument as its argument to ensure the read is allowed.
The UTF-8 charset is used to decode the entry names and comments
| Parameters | |
|---|---|
file |
File!: the ZIP file to be opened for reading |
mode |
Int: the mode in which the file is to be opened |
| Exceptions | |
|---|---|
java.util.zip.ZipException |
if a ZIP format error has occurred |
java.io.IOException |
if an I/O error has occurred |
java.lang.SecurityException |
if a security manager exists and its checkRead method doesn't allow read access to the file, or its checkDelete method doesn't allow deleting the file when the OPEN_DELETE flag is set. |
java.lang.IllegalArgumentException |
if the mode argument is invalid |
ZipFile
ZipFile(file: File!)
Opens a ZIP file for reading given the specified File object.
The UTF-8 charset is used to decode the entry names and comments.
| Parameters | |
|---|---|
file |
File!: the ZIP file to be opened for reading |
| Exceptions | |
|---|---|
java.util.zip.ZipException |
if a ZIP format error has occurred |
java.io.IOException |
if an I/O error has occurred |
ZipFile
ZipFile(
file: File!,
mode: Int,
charset: Charset!)
Opens a new ZipFile to read from the specified File object in the specified mode. The mode argument must be either OPEN_READ or OPEN_READ | OPEN_DELETE.
First, if there is a security manager, its checkRead method is called with the name argument as its argument to ensure the read is allowed.
| Parameters | |
|---|---|
file |
File!: the ZIP file to be opened for reading |
mode |
Int: the mode in which the file is to be opened |
charset |
Charset!: the charset to be used to decode the ZIP entry name and comment that are not encoded by using UTF-8 encoding (indicated by entry's general purpose flag). |
| Exceptions | |
|---|---|
java.util.zip.ZipException |
if a ZIP format error has occurred |
java.io.IOException |
if an I/O error has occurred |
java.lang.SecurityException |
if a security manager exists and its checkRead method doesn't allow read access to the file,or its checkDelete method doesn't allow deleting the file when the OPEN_DELETE flag is set |
java.lang.IllegalArgumentException |
if the mode argument is invalid |
ZipFile
ZipFile(
name: String!,
charset: Charset!)
Opens a zip file for reading.
First, if there is a security manager, its checkRead method is called with the name argument as its argument to ensure the read is allowed.
| Parameters | |
|---|---|
name |
String!: the name of the zip file |
charset |
Charset!: the charset to be used to decode the ZIP entry name and comment that are not encoded by using UTF-8 encoding (indicated by entry's general purpose flag). |
| Exceptions | |
|---|---|
java.util.zip.ZipException |
if a ZIP format error has occurred |
java.io.IOException |
if an I/O error has occurred |
java.lang.SecurityException |
if a security manager exists and its checkRead method doesn't allow read access to the file |
ZipFile
ZipFile(
file: File!,
charset: Charset!)
Opens a ZIP file for reading given the specified File object.
| Parameters | |
|---|---|
file |
File!: the ZIP file to be opened for reading |
charset |
Charset!: The charset to be used to decode the ZIP entry name and comment (ignored if the language encoding bit of the ZIP entry's general purpose bit flag is set). |
| Exceptions | |
|---|---|
java.util.zip.ZipException |
if a ZIP format error has occurred |
java.io.IOException |
if an I/O error has occurred |
Public methods
close
open fun close(): Unit
Closes the ZIP file.
Closing this ZIP file will close all of the input streams previously returned by invocations of the getInputStream method.
| Exceptions | |
|---|---|
java.lang.Exception |
if this resource cannot be closed |
java.io.IOException |
if an I/O error has occurred |
entries
open fun entries(): Enumeration<out ZipEntry!>!
Returns an enumeration of the ZIP file entries.
| Return | |
|---|---|
Enumeration<out ZipEntry!>! |
an enumeration of the ZIP file entries |
| Exceptions | |
|---|---|
java.lang.IllegalStateException |
if the zip file has been closed |
getComment
open fun getComment(): String!
Returns the zip file comment, or null if none.
| Return | |
|---|---|
String! |
the comment string for the zip file, or null if none |
| Exceptions | |
|---|---|
java.lang.IllegalStateException |
if the zip file has been closed Since 1.7 |
getEntry
open fun getEntry(name: String!): ZipEntry!
Returns the zip file entry for the specified name, or null if not found.
| Parameters | |
|---|---|
name |
String!: the name of the entry |
| Return | |
|---|---|
ZipEntry! |
the zip file entry, or null if not found |
| Exceptions | |
|---|---|
java.lang.IllegalStateException |
if the zip file has been closed |
getInputStream
open fun getInputStream(entry: ZipEntry!): InputStream!
Returns an input stream for reading the contents of the specified zip file entry.
Closing this ZIP file will, in turn, close all input streams that have been returned by invocations of this method.
| Parameters | |
|---|---|
entry |
ZipEntry!: the zip file entry |
| Return | |
|---|---|
InputStream! |
the input stream for reading the contents of the specified zip file entry. |
| Exceptions | |
|---|---|
java.util.zip.ZipException |
if a ZIP format error has occurred |
java.io.IOException |
if an I/O error has occurred |
java.lang.IllegalStateException |
if the zip file has been closed |
getName
open fun getName(): String!
Returns the path name of the ZIP file.
| Return | |
|---|---|
String! |
the path name of the ZIP file |
size
open fun size(): Int
Returns the number of entries in the ZIP file.
| Return | |
|---|---|
Int |
the number of entries in the ZIP file |
| Exceptions | |
|---|---|
java.lang.IllegalStateException |
if the zip file has been closed |
stream
open fun stream(): Stream<out ZipEntry!>!
Return an ordered Stream over the ZIP file entries. Entries appear in the Stream in the order they appear in the central directory of the ZIP file.
| Return | |
|---|---|
Stream<out ZipEntry!>! |
an ordered Stream of entries in this ZIP file |
| Exceptions | |
|---|---|
java.lang.IllegalStateException |
if the zip file has been closed |
Protected methods
finalize
protected open fun finalize(): Unit
Ensures that the system resources held by this ZipFile object are released when there are no more references to it.
Since the time when GC would invoke this method is undetermined, it is strongly recommended that applications invoke the close method as soon they have finished accessing this ZipFile. This will prevent holding up system resources for an undetermined length of time.
| Exceptions | |
|---|---|
java.lang.Throwable |
the Exception raised by this method |
java.io.IOException |
if an I/O error has occurred |
See Also