java.util.zip.ZipFile翻译

 
JavaTM 2 Platform
Std. Ed. v1.4.2

java.util.zip
Class ZipFile

java.lang.Object
  extended byjava.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 intCENATT
           
static intCENATX
           
static intCENCOM
           
static intCENCRC
           
static intCENDSK
           
static intCENEXT
           
static intCENFLG
           
static intCENHDR
           
static intCENHOW
           
static intCENLEN
           
static intCENNAM
           
static intCENOFF
           
static longCENSIG
           
static intCENSIZ
           
static intCENTIM
           
static intCENVEM
           
static intCENVER
           
static intENDCOM
           
static intENDHDR
           
static intENDOFF
           
static longENDSIG
           
static intENDSIZ
           
static intENDSUB
           
static intENDTOT
           
static intEXTCRC
           
static intEXTHDR
           
static intEXTLEN
           
static longEXTSIG
           
static intEXTSIZ
           
static intLOCCRC
           
static intLOCEXT
           
static intLOCFLG
           
static intLOCHDR
           
static intLOCHOW
           
static intLOCLEN
           
static intLOCNAM
           
static longLOCSIG
           
static intLOCSIZ
           
static intLOCTIM
           
static intLOCVER
           
static intOPEN_DELETE
          Mode flag to open a zip file and mark it for deletion. zip文件打开的模式标记,标记为删除。
static intOPEN_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
 voidclose()
          Closes the ZIP file. 关闭ZIP文件。
 Enumerationentries()
          Returns an enumeration of the ZIP file entries. 返回ZIP文件项的枚举。
protected  voidfinalize()
          Ensures that the close method of this ZIP file is called when there are no more references to it. 确保没有对ZIP文件的引用时,调用close方法。
 ZipEntrygetEntry(String name)
          Returns the zip file entry for the specified name, or null if not found. 返回给定名称的zip文件项,如果未找到,返回null。
 InputStreamgetInputStream(ZipEntry entry)
          Returns an input stream for reading the contents of the specified zip file entry. 返回读取指定zip文件项内容的输入流。
 StringgetName()
          Returns the path name of the ZIP file. 返回ZIP文件的路径名。
 intsize()
          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
See Also:
Constant Field Values

EXTSIG

public static final long EXTSIG
See Also:
Constant Field Values

CENSIG

public static final long CENSIG
See Also:
Constant Field Values

ENDSIG

public static final long ENDSIG
See Also:
Constant Field Values

LOCHDR

public static final int LOCHDR
See Also:
Constant Field Values

EXTHDR

public static final int EXTHDR
See Also:
Constant Field Values

CENHDR

public static final int CENHDR
See Also:
Constant Field Values

ENDHDR

public static final int ENDHDR
See Also:
Constant Field Values

LOCVER

public static final int LOCVER
See Also:
Constant Field Values

LOCFLG

public static final int LOCFLG
See Also:
Constant Field Values

LOCHOW

public static final int LOCHOW
See Also:
Constant Field Values

LOCTIM

public static final int LOCTIM
See Also:
Constant Field Values

LOCCRC

public static final int LOCCRC
See Also:
Constant Field Values

LOCSIZ

public static final int LOCSIZ
See Also:
Constant Field Values

LOCLEN

public static final int LOCLEN
See Also:
Constant Field Values

LOCNAM

public static final int LOCNAM
See Also:
Constant Field Values

LOCEXT

public static final int LOCEXT
See Also:
Constant Field Values

EXTCRC

public static final int EXTCRC
See Also:
Constant Field Values

EXTSIZ

public static final int EXTSIZ
See Also:
Constant Field Values

EXTLEN

public static final int EXTLEN
See Also:
Constant Field Values

CENVEM

public static final int CENVEM
See Also:
Constant Field Values

CENVER

public static final int CENVER
See Also:
Constant Field Values

CENFLG

public static final int CENFLG
See Also:
Constant Field Values

CENHOW

public static final int CENHOW
See Also:
Constant Field Values

CENTIM

public static final int CENTIM
See Also:
Constant Field Values

CENCRC

public static final int CENCRC
See Also:
Constant Field Values

CENSIZ

public static final int CENSIZ
See Also:
Constant Field Values

CENLEN

public static final int CENLEN
See Also:
Constant Field Values

CENNAM

public static final int CENNAM
See Also:
Constant Field Values

CENEXT

public static final int CENEXT
See Also:
Constant Field Values

CENCOM

public static final int CENCOM
See Also:
Constant Field Values

CENDSK

public static final int CENDSK
See Also:
Constant Field Values

CENATT

public static final int CENATT
See Also:
Constant Field Values

CENATX

public static final int CENATX
See Also:
Constant Field Values

CENOFF

public static final int CENOFF
See Also:
Constant Field Values

ENDSUB

public static final int ENDSUB
See Also:
Constant Field Values

ENDTOT

public static final int ENDTOT
See Also:
Constant Field Values

ENDSIZ

public static final int ENDSIZ
See Also:
Constant Field Values

ENDOFF

public static final int ENDOFF
See Also:
Constant Field Values

ENDCOM

public static final int ENDCOM
See Also:
Constant Field Values
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 the name 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 its checkRead 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 specified File 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 the name 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 its checkRead method doesn't allow read access to the file, or checkDelete 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 this ZipFile. This will prevent holding up system resources for an undetermined length of time. 因为GC调用此方法的时间不能确定,因此强烈建议应用程序一旦完成ZipFile的访问, 立即调用close方法。这将避免长时间的占用系统资源。

Overrides:
finalize in class Object
Throws:
IOException - if an I/O error occurs. 如果发生I/O错误抛出。
See Also:
close()

JavaTM 2 Platform
Std. Ed. v1.4.2

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值