| JavaTM 2 Platform Std. Ed. v1.4.2 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES <script type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> </script> All Classes | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.util.zip
Class ZipFile
java.lang.Objectjava.util.zip.ZipFile
-
All Implemented Interfaces:
- java.util.zip.ZipConstants
-
Direct Known Subclasses:
- JarFile
-
public class ZipFile
extends
Object
implements java.util.zip.ZipConstants
This class is used to read entries from a zip file. 用于从zip文件中读取项的类。
Field Summary | |
static int | CENATT |
static int | CENATX |
static int | CENCOM |
static int | CENCRC |
static int | CENDSK |
static int | CENEXT |
static int | CENFLG |
static int | CENHDR |
static int | CENHOW |
static int | CENLEN |
static int | CENNAM |
static int | CENOFF |
static long | CENSIG |
static int | CENSIZ |
static int | CENTIM |
static int | CENVEM |
static int | CENVER |
static int | ENDCOM |
static int | ENDHDR |
static int | ENDOFF |
static long | ENDSIG |
static int | ENDSIZ |
static int | ENDSUB |
static int | ENDTOT |
static int | EXTCRC |
static int | EXTHDR |
static int | EXTLEN |
static long | EXTSIG |
static int | EXTSIZ |
static int | LOCCRC |
static int | LOCEXT |
static int | LOCFLG |
static int | LOCHDR |
static int | LOCHOW |
static int | LOCLEN |
static int | LOCNAM |
static long | LOCSIG |
static int | LOCSIZ |
static int | LOCTIM |
static int | LOCVER |
static int | OPEN_DELETE Mode flag to open a zip file and mark it for deletion. zip文件打开的模式标记,标记为删除。 |
static int | OPEN_READ Mode flag to open a zip file for reading. zip文件打开的模式标记,标记为读取。 |
Constructor Summary | |
ZipFile(File file) Opens a ZIP file for reading given the specified File object. 打开一个ZIP文件来读取指定的File对象。 | |
ZipFile(File file, int mode) Opens a new ZipFile to read from the specified File object in the specified mode. 打开一个ZipFile,按指定的模式读取指定的File对象。 | |
ZipFile(String name) Opens a zip file for reading. 打开一个要读取的zip文件。 |
Method Summary | |
void | close() Closes the ZIP file. 关闭ZIP文件。 |
Enumeration | entries() Returns an enumeration of the ZIP file entries. 返回ZIP文件项的枚举。 |
protected void | finalize() Ensures that the close method of this ZIP file is called when there are no more references to it. 确保没有对ZIP文件的引用时,调用close方法。 |
ZipEntry | getEntry(String name) Returns the zip file entry for the specified name, or null if not found. 返回给定名称的zip文件项,如果未找到,返回null。 |
InputStream | getInputStream(ZipEntry entry) Returns an input stream for reading the contents of the specified zip file entry. 返回读取指定zip文件项内容的输入流。 |
String | getName() Returns the path name of the ZIP file. 返回ZIP文件的路径名。 |
int | size() Returns the number of entries in the ZIP file. 返回ZIP文件中项的数目。 |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
OPEN_READ
public static final int OPEN_READ
-
Mode flag to open a zip file for reading. zip文件打开的模式标记,标记为读取。
-
See Also:
- Constant Field Values
OPEN_DELETE
public static final int OPEN_DELETE
-
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. zip文件打开的模式标记,标记为删除。删除文件一般在打开时刻和关闭时刻之间,但其内容仍然 可以通过ZipFile对象进行访问直到调用close方法或者虚拟机退出。
-
See Also:
- Constant Field Values
LOCSIG
public static final long LOCSIG
- Constant Field Values
-
See Also:
EXTSIG
public static final long EXTSIG
- Constant Field Values
-
See Also:
CENSIG
public static final long CENSIG
- Constant Field Values
-
See Also:
ENDSIG
public static final long ENDSIG
- Constant Field Values
-
See Also:
LOCHDR
public static final int LOCHDR
- Constant Field Values
-
See Also:
EXTHDR
public static final int EXTHDR
- Constant Field Values
-
See Also:
CENHDR
public static final int CENHDR
- Constant Field Values
-
See Also:
ENDHDR
public static final int ENDHDR
- Constant Field Values
-
See Also:
LOCVER
public static final int LOCVER
- Constant Field Values
-
See Also:
LOCFLG
public static final int LOCFLG
- Constant Field Values
-
See Also:
LOCHOW
public static final int LOCHOW
- Constant Field Values
-
See Also:
LOCTIM
public static final int LOCTIM
- Constant Field Values
-
See Also:
LOCCRC
public static final int LOCCRC
- Constant Field Values
-
See Also:
LOCSIZ
public static final int LOCSIZ
- Constant Field Values
-
See Also:
LOCLEN
public static final int LOCLEN
- Constant Field Values
-
See Also:
LOCNAM
public static final int LOCNAM
- Constant Field Values
-
See Also:
LOCEXT
public static final int LOCEXT
- Constant Field Values
-
See Also:
EXTCRC
public static final int EXTCRC
- Constant Field Values
-
See Also:
EXTSIZ
public static final int EXTSIZ
- Constant Field Values
-
See Also:
EXTLEN
public static final int EXTLEN
- Constant Field Values
-
See Also:
CENVEM
public static final int CENVEM
- Constant Field Values
-
See Also:
CENVER
public static final int CENVER
- Constant Field Values
-
See Also:
CENFLG
public static final int CENFLG
- Constant Field Values
-
See Also:
CENHOW
public static final int CENHOW
- Constant Field Values
-
See Also:
CENTIM
public static final int CENTIM
- Constant Field Values
-
See Also:
CENCRC
public static final int CENCRC
- Constant Field Values
-
See Also:
CENSIZ
public static final int CENSIZ
- Constant Field Values
-
See Also:
CENLEN
public static final int CENLEN
- Constant Field Values
-
See Also:
CENNAM
public static final int CENNAM
- Constant Field Values
-
See Also:
CENEXT
public static final int CENEXT
- Constant Field Values
-
See Also:
CENCOM
public static final int CENCOM
- Constant Field Values
-
See Also:
CENDSK
public static final int CENDSK
- Constant Field Values
-
See Also:
CENATT
public static final int CENATT
- Constant Field Values
-
See Also:
CENATX
public static final int CENATX
- Constant Field Values
-
See Also:
CENOFF
public static final int CENOFF
- Constant Field Values
-
See Also:
ENDSUB
public static final int ENDSUB
- Constant Field Values
-
See Also:
ENDTOT
public static final int ENDTOT
- Constant Field Values
-
See Also:
ENDSIZ
public static final int ENDSIZ
- Constant Field Values
-
See Also:
ENDOFF
public static final int ENDOFF
- Constant Field Values
-
See Also:
ENDCOM
public static final int ENDCOM
- Constant Field Values
-
See Also:
Constructor Detail |
ZipFile
public ZipFile(String name) throws IOException
-
Opens a zip file for reading. 打开一个要读取的zip文件。
First, if there is a security manager, its
checkRead
method is called with thename
argument as its argument to ensure the read is allowed. 如果存在安全管理器,首先使用name参数作为它的参数调用checkRead方法,来确认允许读取。
Parameters:
-
name
- the name of the zip file zip文件名
Throws:
-
ZipException
- if a ZIP format error has occurred 如果发生ZIP格式错误抛出 -
IOException
- if an I/O error has occurred 如果发生I/O错误抛出 -
SecurityException
- if a security manager exists and itscheckRead
method doesn't allow read access to the file. 如果安全管理器存在,它的checkRead方法不允许读取该文件时抛出。
See Also:
-
SecurityManager.checkRead(java.lang.String)
ZipFile
public ZipFile(File file, int mode) throws IOException
-
Opens a new
ZipFile
to read from the specifiedFile
object in the specified mode. The mode argument must be either OPEN_READ or OPEN_READ | OPEN_DELETE. 打开一个ZipFile,按指定的模式读取指定的File对象。First, if there is a security manager, its
checkRead
method is called with thename
argument as its argument to ensure the read is allowed. 如果存在安全管理器,首先使用name参数作为它的参数调用checkRead方法,来确认允许读取。
Parameters:
-
file
- the ZIP file to be opened for reading 要打开读取的ZIP文件 -
mode
- the mode in which the file is to be opened 文件要打开的模式
Throws:
-
ZipException
- if a ZIP format error has occurred 如果发生ZIP格式错误抛出 -
IOException
- if an I/O error has occurred 如果发生I/O错误抛出 -
SecurityException
- if a security manager exists and itscheckRead
method doesn't allow read access to the file, orcheckDelete
method doesn't allow deleting the file when OPEN_DELETE flag is set. 如果安全管理器存在且设置OPEN_DELETE标记,它的checkRead方法不允许读取该文件,或者checkDelete不允许删除该文件时抛出。 -
IllegalArgumentException
- If the mode argument is invalid 如果mode参数无效抛出
See Also:
-
SecurityManager.checkRead(java.lang.String)
ZipFile
public ZipFile(File file) throws ZipException, IOException
- Opens a ZIP file for reading given the specified File object. 打开一个ZIP文件来读取指定的File对象。 Parameters:
-
file
- the ZIP file to be opened for reading 要打开读取的ZIP文件
Throws:
-
ZipException
- if a ZIP error has occurred 如果发生ZIP格式错误抛出 -
IOException
- if an I/O error has occurred 如果发生I/O错误抛出
Method Detail |
getEntry
public ZipEntry getEntry(String name)
- Returns the zip file entry for the specified name, or null if not found. 返回给定名称的zip文件项,如果未找到,返回null。
-
-
-
Parameters:
-
name
- the name of the entry 项的名称
Returns:
- the zip file entry, or null if not found zip文件项,如果未找到,返回null。 Throws:
-
IllegalStateException
- if the zip file has been closed 如果zip文件已被关闭抛出
-
getInputStream
public InputStream getInputStream(ZipEntry entry) throws IOException
-
Returns an input stream for reading the contents of the specified zip file entry. 返回读取指定zip文件项内容的输入流。
Closing this ZIP file will, in turn, close all input streams that have been returned by invocations of this method. 关闭ZIP文件,将同时关闭调用该方法返回的所有输入流。
-
-
-
Parameters:
-
entry
- the zip file entry zip文件项
Returns:
- the input stream for reading the contents of the specified zip file entry. 读取指定zip文件项内容的输入流。 Throws:
-
ZipException
- if a ZIP format error has occurred 如果发生ZIP格式错误抛出 -
IOException
- if an I/O error has occurred 如果发生I/O错误抛出 -
IllegalStateException
- if the zip file has been closed 如果zip文件已被关闭抛出
-
getName
public String getName()
- Returns the path name of the ZIP file. 返回ZIP文件的路径名。
-
-
-
Returns:
- the path name of the ZIP file ZIP文件的路径名
entries
public Enumeration entries()
- Returns an enumeration of the ZIP file entries. 返回ZIP文件项的枚举。
-
-
-
Returns:
- an enumeration of the ZIP file entries ZIP文件项的枚举。 Throws:
-
IllegalStateException
- if the zip file has been closed 如果zip文件已被关闭抛出
size
public int size()
- Returns the number of entries in the ZIP file. 返回ZIP文件中项的数目。
-
-
-
Returns:
- the number of entries in the ZIP file ZIP文件中项的数目 Throws:
-
IllegalStateException
- if the zip file has been closed 如果zip文件已被关闭抛出
close
public void close() throws IOException
-
Closes the ZIP file. 关闭ZIP文件。
Closing this ZIP file will close all of the input streams previously returned by invocations of the
getInputStream
method. 关闭ZIP文件,将同时关闭之前调用getInputStream方法返回的所有输入流。 -
-
-
Throws:
-
IOException
- if an I/O error has occured 如果发生I/O错误抛出
-
finalize
protected void finalize() throws IOException
-
Ensures that the
close
method of this ZIP file is called when there are no more references to it. 确保没有对ZIP文件的引用时,调用close方法。Since the time when GC would invoke this method is undetermined, it is strongly recommanded that applications invoke the
close
method as soon they have finished accessing thisZipFile
. This will prevent holding up system resources for an undetermined length of time. 因为GC调用此方法的时间不能确定,因此强烈建议应用程序一旦完成ZipFile的访问, 立即调用close方法。这将避免长时间的占用系统资源。 -
-
Throws:
-
IOException
- if an I/O error occurs. 如果发生I/O错误抛出。
See Also:
-
close()
-
| JavaTM 2 Platform Std. Ed. v1.4.2 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES <script type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> </script> All Classes | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation . That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.