Most visited

Recently visited

Added in API level 1

ZipFile

public class ZipFile
extends Object implements Closeable

java.lang.Object
   ↳ java.util.zip.ZipFile
Known Direct Subclasses


该类用于读取zip文件中的条目。

除非另有说明,否则将 null参数传递给 此类中的构造函数或方法将导致引发 NullPointerException

Summary

Constants

int CENATT

int CENATX

int CENCOM

int CENCRC

int CENDSK

int CENEXT

int CENFLG

int CENHDR

int CENHOW

int CENLEN

int CENNAM

int CENOFF

long CENSIG

int CENSIZ

int CENTIM

int CENVEM

int CENVER

int ENDCOM

int ENDHDR

int ENDOFF

long ENDSIG

int ENDSIZ

int ENDSUB

int ENDTOT

int EXTCRC

int EXTHDR

int EXTLEN

long EXTSIG

int EXTSIZ

int LOCCRC

int LOCEXT

int LOCFLG

int LOCHDR

int LOCHOW

int LOCLEN

int LOCNAM

long LOCSIG

int LOCSIZ

int LOCTIM

int LOCVER

int OPEN_DELETE

模式标志打开一个zip文件并将其标记为删除。

int OPEN_READ

模式标志打开一个zip文件进行阅读。

Public constructors

ZipFile(String name)

打开一个zip文件进行阅读。

ZipFile(File file, int mode)

打开一个新的 ZipFile以从指定模式下的指定 File对象读取。

ZipFile(File file)

给定指定的File对象,打开ZIP文件进行读取。

ZipFile(File file, int mode, Charset charset)

打开新的 ZipFile以从指定模式下的指定 File对象读取。

ZipFile(String name, Charset charset)

打开一个zip文件进行阅读。

ZipFile(File file, Charset charset)

给定指定的File对象,打开ZIP文件进行读取。

Public methods

void close()

关闭ZIP文件。

Enumeration<? extends ZipEntry> entries()

返回ZIP文件条目的枚举。

String getComment()

返回压缩文件注释,如果没有,则返回null。

ZipEntry getEntry(String name)

返回指定名称的zip文件条目,如果未找到,则返回null。

InputStream getInputStream(ZipEntry entry)

返回用于读取指定zip文件条目内容的输入流。

String getName()

返回ZIP文件的路径名称。

int size()

返回ZIP文件中的条目数。

Protected methods

void finalize()

确保此ZipFile对象所持有的系统资源在没有更多引用时被释放。

Inherited methods

From class java.lang.Object
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Constants

CENATT

Added in API level 21
int CENATT

常量值:36(0x00000024)

CENATX

Added in API level 21
int CENATX

常量值:38(0x00000026)

CENCOM

Added in API level 21
int CENCOM

常量值:32(0x00000020)

CENCRC

Added in API level 21
int CENCRC

常量值:16(0x00000010)

CENDSK

Added in API level 21
int CENDSK

常量值:34(0x00000022)

CENEXT

Added in API level 21
int CENEXT

常量值:30(0x0000001e)

CENFLG

Added in API level 21
int CENFLG

常量值:8(0x00000008)

CENHDR

Added in API level 21
int CENHDR

常量值:46(0x0000002e)

CENHOW

Added in API level 21
int CENHOW

常量值:10(0x0000000a)

CENLEN

Added in API level 21
int CENLEN

常量值:24(0x00000018)

CENNAM

Added in API level 21
int CENNAM

常量值:28(0x0000001c)

CENOFF

Added in API level 21
int CENOFF

常量值:42(0x0000002a)

CENSIG

Added in API level 21
long CENSIG

常量值:33639248(0x0000000002014b50)

CENSIZ

Added in API level 21
int CENSIZ

常量值:20(0x00000014)

CENTIM

Added in API level 21
int CENTIM

常量值:12(0x0000000c)

CENVEM

Added in API level 21
int CENVEM

常量值:4(0x00000004)

CENVER

Added in API level 21
int CENVER

常数值:6(0x00000006)

ENDCOM

Added in API level 21
int ENDCOM

常量值:20(0x00000014)

ENDHDR

Added in API level 21
int ENDHDR

常量值:22(0x00000016)

ENDOFF

Added in API level 21
int ENDOFF

常量值:16(0x00000010)

ENDSIG

Added in API level 21
long ENDSIG

常量值:101010256(0x0000000006054b50)

ENDSIZ

Added in API level 21
int ENDSIZ

常量值:12(0x0000000c)

ENDSUB

Added in API level 21
int ENDSUB

常量值:8(0x00000008)

ENDTOT

Added in API level 21
int ENDTOT

常量值:10(0x0000000a)

EXTCRC

Added in API level 21
int EXTCRC

常量值:4(0x00000004)

EXTHDR

Added in API level 21
int EXTHDR

常量值:16(0x00000010)

EXTLEN

Added in API level 21
int EXTLEN

常量值:12(0x0000000c)

EXTSIG

Added in API level 21
long EXTSIG

常量值:134695760(0x0000000008074b50)

EXTSIZ

Added in API level 21
int EXTSIZ

常量值:8(0x00000008)

LOCCRC

Added in API level 21
int LOCCRC

常量值:14(0x0000000e)

LOCEXT

Added in API level 21
int LOCEXT

常量值:28(0x0000001c)

LOCFLG

Added in API level 21
int LOCFLG

常数值:6(0x00000006)

LOCHDR

Added in API level 21
int LOCHDR

常量值:30(0x0000001e)

LOCHOW

Added in API level 21
int LOCHOW

常量值:8(0x00000008)

LOCLEN

Added in API level 21
int LOCLEN

常量值:22(0x00000016)

LOCNAM

Added in API level 21
int LOCNAM

常量值:26(0x0000001a)

LOCSIG

Added in API level 21
long LOCSIG

常量值:67324752(0x0000000004034b50)

LOCSIZ

Added in API level 21
int LOCSIZ

常量值:18(0x00000012)

LOCTIM

Added in API level 21
int LOCTIM

常量值:10(0x0000000a)

LOCVER

Added in API level 21
int LOCVER

常量值:4(0x00000004)

OPEN_DELETE

Added in API level 1
int OPEN_DELETE

模式标志打开一个zip文件并将其标记为删除。 该文件将在打开和关闭时间之间被删除一段时间,但其内容仍可通过ZipFile对象访问,直到调用close方法或虚拟机退出。

常量值:4(0x00000004)

OPEN_READ

Added in API level 1
int OPEN_READ

模式标志打开一个zip文件进行阅读。

常数值:1(0x00000001)

Public constructors

ZipFile

Added in API level 1
ZipFile (String name)

打开一个zip文件进行阅读。

首先,如果存在安全管理器,则使用 name参数调用其 checkRead方法,以确保允许读取。

UTF-8 charset用于解码条目名称和注释。

Parameters
name String: the name of the zip file
Throws
ZipException if a ZIP format error has occurred
IOException if an I/O error has occurred
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, 
                int mode)

打开新的ZipFile以从指定模式下的指定File对象读取。 模式参数必须是OPEN_READOPEN_READ | OPEN_DELETE

首先,如果存在安全管理器,则使用 name参数作为其参数调用其 checkRead方法,以确保允许读取。

UTF-8 charset用于解码条目名称和注释

Parameters
file File: the ZIP file to be opened for reading
mode int: the mode in which the file is to be opened
Throws
ZipException if a ZIP format error has occurred
IOException if an I/O error has occurred
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.
IllegalArgumentException if the mode argument is invalid

也可以看看:

ZipFile

Added in API level 1
ZipFile (File file)

给定指定的File对象,打开ZIP文件进行读取。

UTF-8 charset用于解码条目名称和注释。

Parameters
file File: the ZIP file to be opened for reading
Throws
ZipException if a ZIP format error has occurred
IOException if an I/O error has occurred

ZipFile

Added in API level 24
ZipFile (File file, 
                int mode, 
                Charset charset)

打开新的ZipFile以从指定模式下的指定File对象读取。 模式参数必须是OPEN_READOPEN_READ | OPEN_DELETE

首先,如果存在安全管理器,则使用 name参数作为参数调用其 checkRead方法,以确保允许读取。

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).
Throws
ZipException if a ZIP format error has occurred
IOException if an I/O error has occurred
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
IllegalArgumentException if the mode argument is invalid

也可以看看:

ZipFile

Added in API level 24
ZipFile (String name, 
                Charset charset)

打开一个zip文件进行阅读。

首先,如果存在安全管理器,则使用 name参数作为参数调用其 checkRead方法,以确保允许读取。

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).
Throws
ZipException if a ZIP format error has occurred
IOException if an I/O error has occurred
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)

给定指定的File对象,打开ZIP文件进行读取。

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).
Throws
ZipException if a ZIP format error has occurred
IOException if an I/O error has occurred

Public methods

close

Added in API level 1
void close ()

关闭ZIP文件。

关闭此ZIP文件将关闭以前由调用 getInputStream方法返回的所有输入流。

Throws
IOException if an I/O error has occurred

entries

Added in API level 1
Enumeration<? extends ZipEntry> entries ()

返回ZIP文件条目的枚举。

Returns
Enumeration<? extends ZipEntry> an enumeration of the ZIP file entries
Throws
IllegalStateException if the zip file has been closed

getComment

Added in API level 19
String getComment ()

返回压缩文件注释,如果没有,则返回null。

Returns
String the comment string for the zip file, or null if none
Throws
IllegalStateException if the zip file has been closed Since 1.7

getEntry

Added in API level 1
ZipEntry getEntry (String name)

返回指定名称的zip文件条目,如果未找到,则返回null。

Parameters
name String: the name of the entry
Returns
ZipEntry the zip file entry, or null if not found
Throws
IllegalStateException if the zip file has been closed

getInputStream

Added in API level 1
InputStream getInputStream (ZipEntry entry)

返回用于读取指定zip文件条目内容的输入流。

关闭此ZIP文件将依次关闭通过调用此方法返回的所有输入流。

Parameters
entry ZipEntry: the zip file entry
Returns
InputStream the input stream for reading the contents of the specified zip file entry.
Throws
ZipException if a ZIP format error has occurred
IOException if an I/O error has occurred
IllegalStateException if the zip file has been closed

getName

Added in API level 1
String getName ()

返回ZIP文件的路径名称。

Returns
String the path name of the ZIP file

size

Added in API level 1
int size ()

返回ZIP文件中的条目数。

Returns
int the number of entries in the ZIP file
Throws
IllegalStateException if the zip file has been closed

Protected methods

finalize

Added in API level 1
void finalize ()

确保此ZipFile对象所持有的系统资源在没有更多引用时被释放。

由于GC调用此方法的时间未确定,因此强烈建议应用程序在完成访问此ZipFile后尽快调用close方法。 这将阻止系统资源长时间不确定。

Throws
IOException if an I/O error has occurred

也可以看看:

Hooray!