public class ZipFile
extends Object
implements Closeable
java.lang.Object | |
↳ | java.util.zip.ZipFile |
Known Direct Subclasses |
该类用于读取zip文件中的条目。
除非另有说明,否则将 null参数传递给 此类中的构造函数或方法将导致引发 NullPointerException
。
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 file) 给定指定的File对象,打开ZIP文件进行读取。 |
|
ZipFile(File file, int mode, Charset charset) 打开新的 |
|
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
|
int OPEN_DELETE
模式标志打开一个zip文件并将其标记为删除。 该文件将在打开和关闭时间之间被删除一段时间,但其内容仍可通过ZipFile对象访问,直到调用close方法或虚拟机退出。
常量值:4(0x00000004)
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 (File file, int mode)
打开新的ZipFile
以从指定模式下的指定File
对象读取。 模式参数必须是OPEN_READ或OPEN_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 (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 (File file, int mode, Charset charset)
打开新的ZipFile
以从指定模式下的指定File
对象读取。 模式参数必须是OPEN_READ或OPEN_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 (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 (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 |
void close ()
关闭ZIP文件。
关闭此ZIP文件将关闭以前由调用 getInputStream
方法返回的所有输入流。
Throws | |
---|---|
IOException |
if an I/O error has occurred |
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 |
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 |
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 |
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 |
String getName ()
返回ZIP文件的路径名称。
Returns | |
---|---|
String |
the path name of the ZIP file |
int size ()
返回ZIP文件中的条目数。
Returns | |
---|---|
int |
the number of entries in the ZIP file |
Throws | |
---|---|
IllegalStateException |
if the zip file has been closed |
void finalize ()
确保此ZipFile对象所持有的系统资源在没有更多引用时被释放。
由于GC调用此方法的时间未确定,因此强烈建议应用程序在完成访问此ZipFile
后尽快调用close
方法。 这将阻止系统资源长时间不确定。
Throws | |
---|---|
IOException |
if an I/O error has occurred |
也可以看看: