Added in API level 1

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
ZipFile(name: String!)

Opens a zip file for reading.

ZipFile(file: File!, mode: Int)

Opens a new ZipFile to read from the specified File object in the specified mode.

ZipFile(file: File!)

Opens a ZIP file for reading given the specified File object.

ZipFile(file: File!, mode: Int, charset: Charset!)

Opens a new ZipFile to read from the specified File object in the specified mode.

ZipFile(name: String!, charset: Charset!)

Opens a zip file for reading.

ZipFile(file: File!, charset: Charset!)

Opens a ZIP file for reading given the specified File object.

Public methods
open Unit

Closes the ZIP file.

open Enumeration<out ZipEntry!>!

Returns an enumeration of the ZIP file entries.

open String!

Returns the zip file comment, or null if none.

open ZipEntry!
getEntry(name: String!)

Returns the zip file entry for the specified name, or null if not found.

open InputStream!

Returns an input stream for reading the contents of the specified zip file entry.

open String!

Returns the path name of the ZIP file.

open Int

Returns the number of entries in the ZIP file.

open Stream<out ZipEntry!>!

Return an ordered Stream over the ZIP file entries.

Protected methods
open Unit

Ensures that the system resources held by this ZipFile object are released when there are no more references to it.

Constants

CENATT

Added in API level 21
static val CENATT: Int
Value: 36

CENATX

Added in API level 21
static val CENATX: Int
Value: 38

CENCOM

Added in API level 21
static val CENCOM: Int
Value: 32

CENCRC

Added in API level 21
static val CENCRC: Int
Value: 16

CENDSK

Added in API level 21
static val CENDSK: Int
Value: 34

CENEXT

Added in API level 21
static val CENEXT: Int
Value: 30

CENFLG

Added in API level 21
static val CENFLG: Int
Value: 8

CENHDR

Added in API level 21
static val CENHDR: Int
Value: 46

CENHOW

Added in API level 21
static val CENHOW: Int
Value: 10

CENLEN

Added in API level 21
static val CENLEN: Int
Value: 24

CENNAM

Added in API level 21
static val CENNAM: Int
Value: 28

CENOFF

Added in API level 21
static val CENOFF: Int
Value: 42

CENSIG

Added in API level 21
static val CENSIG: Long
Value: 33639248L

CENSIZ

Added in API level 21
static val CENSIZ: Int
Value: 20

CENTIM

Added in API level 21
static val CENTIM: Int
Value: 12

CENVEM

Added in API level 21
static val CENVEM: Int
Value: 4

CENVER

Added in API level 21
static val CENVER: Int
Value: 6

ENDCOM

Added in API level 21
static val ENDCOM: Int
Value: 20

ENDHDR

Added in API level 21
static val ENDHDR: Int
Value: 22

ENDOFF

Added in API level 21
static val ENDOFF: Int
Value: 16

ENDSIG

Added in API level 21
static val ENDSIG: Long
Value: 101010256L

ENDSIZ

Added in API level 21
static val ENDSIZ: Int
Value: 12

ENDSUB

Added in API level 21
static val ENDSUB: Int
Value: 8

ENDTOT

Added in API level 21
static val ENDTOT: Int
Value: 10

EXTCRC

Added in API level 21
static val EXTCRC: Int
Value: 4

EXTHDR

Added in API level 21
static val EXTHDR: Int
Value: 16

EXTLEN

Added in API level 21
static val EXTLEN: Int
Value: 12

EXTSIG

Added in API level 21
static val EXTSIG: Long
Value: 134695760L

EXTSIZ

Added in API level 21
static val EXTSIZ: Int
Value: 8

LOCCRC

Added in API level 21
static val LOCCRC: Int
Value: 14

LOCEXT

Added in API level 21
static val LOCEXT: Int
Value: 28

LOCFLG

Added in API level 21
static val LOCFLG: Int
Value: 6

LOCHDR

Added in API level 21
static val LOCHDR: Int
Value: 30

LOCHOW

Added in API level 21
static val LOCHOW: Int
Value: 8

LOCLEN

Added in API level 21
static val LOCLEN: Int
Value: 22

LOCNAM

Added in API level 21
static val LOCNAM: Int
Value: 26

LOCSIG

Added in API level 21
static val LOCSIG: Long
Value: 67324752L

LOCSIZ

Added in API level 21
static val LOCSIZ: Int
Value: 18

LOCTIM

Added in API level 21
static val LOCTIM: Int
Value: 10

LOCVER

Added in API level 21
static val LOCVER: Int
Value: 4

OPEN_DELETE

Added in API level 1
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

Added in API level 1
static val OPEN_READ: Int

Mode flag to open a zip file for reading.

Value: 1

Public constructors

ZipFile

Added in API level 1
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

Added in API level 1
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

Added in API level 1
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

Added in API level 24
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

Added in API level 24
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

Added in API level 24
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

Added in API level 1
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

Added in API level 1
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

Added in API level 19
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

Added in API level 1
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

Added in API level 1
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

Added in API level 1
open fun getName(): String!

Returns the path name of the ZIP file.

Return
String! the path name of the ZIP file

size

Added in API level 1
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

Added in API level 26
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

Added in API level 1
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