java.util.zip类 ZipFile

来源:互联网 发布:网络视听节目审核通则 编辑:程序博客网 时间:2024/06/05 23:50

java.util.zip
类 ZipFile

java.lang.Object  继承者 java.util.zip.ZipFile
直接已知子类:
JarFile

public class ZipFile
extends Object

此类用于从 ZIP 文件读取条目。

除非另有说明,将 null 参数传入此类中的构造方法或方法将导致抛出 NullPointerException。


字段摘要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
          打开 ZIP 文件并将其标记为删除的模式标志。static intOPEN_READ
          打开 ZIP 文件进行阅读的模式标志。 构造方法摘要ZipFile(File file)
          打开供阅读的 ZIP 文件,由指定的 File 对象给出。ZipFile(File file, int mode)
          打开新的 ZipFile 以使用指定模式从指定 File 对象读取。ZipFile(String name)
          打开 ZIP 文件进行阅读。 方法摘要 voidclose()
          关闭 ZIP 文件。 Enumeration<? extends ZipEntry>entries()
          返回 ZIP 文件条目的枚举。protected  voidfinalize()
          确保不再引用此 ZIP 文件时调用它的 close 方法。 ZipEntrygetEntry(String name)
          返回指定名称的 ZIP 文件条目;如果未找到,则返回 null。 InputStreamgetInputStream(ZipEntry entry)
          返回输入流以读取指定 ZIP 文件条目的内容。 StringgetName()
          返回 ZIP 文件的路径名。 intsize()
          返回 ZIP 文件中的条目数。 从类 java.lang.Object 继承的方法clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 

字段详细信息

OPEN_READ

public static final int OPEN_READ
打开 ZIP 文件进行阅读的模式标志。

另请参见:
常量字段值

OPEN_DELETE

public static final int OPEN_DELETE
打开 ZIP 文件并将其标记为删除的模式标志。在打开文件和关闭文件之间的某个时间,该文件将被删除,但是其内容仍可通过 ZipFile 对象访问,直到调用关闭方法或虚拟机退出为止。

另请参见:
常量字段值

LOCSIG

public static final long LOCSIG
另请参见:
常量字段值

EXTSIG

public static final long EXTSIG
另请参见:
常量字段值

CENSIG

public static final long CENSIG
另请参见:
常量字段值

ENDSIG

public static final long ENDSIG
另请参见:
常量字段值

LOCHDR

public static final int LOCHDR
另请参见:
常量字段值

EXTHDR

public static final int EXTHDR
另请参见:
常量字段值

CENHDR

public static final int CENHDR
另请参见:
常量字段值

ENDHDR

public static final int ENDHDR
另请参见:
常量字段值

LOCVER

public static final int LOCVER
另请参见:
常量字段值

LOCFLG

public static final int LOCFLG
另请参见:
常量字段值

LOCHOW

public static final int LOCHOW
另请参见:
常量字段值

LOCTIM

public static final int LOCTIM
另请参见:
常量字段值

LOCCRC

public static final int LOCCRC
另请参见:
常量字段值

LOCSIZ

public static final int LOCSIZ
另请参见:
常量字段值

LOCLEN

public static final int LOCLEN
另请参见:
常量字段值

LOCNAM

public static final int LOCNAM
另请参见:
常量字段值

LOCEXT

public static final int LOCEXT
另请参见:
常量字段值

EXTCRC

public static final int EXTCRC
另请参见:
常量字段值

EXTSIZ

public static final int EXTSIZ
另请参见:
常量字段值

EXTLEN

public static final int EXTLEN
另请参见:
常量字段值

CENVEM

public static final int CENVEM
另请参见:
常量字段值

CENVER

public static final int CENVER
另请参见:
常量字段值

CENFLG

public static final int CENFLG
另请参见:
常量字段值

CENHOW

public static final int CENHOW
另请参见:
常量字段值

CENTIM

public static final int CENTIM
另请参见:
常量字段值

CENCRC

public static final int CENCRC
另请参见:
常量字段值

CENSIZ

public static final int CENSIZ
另请参见:
常量字段值

CENLEN

public static final int CENLEN
另请参见:
常量字段值

CENNAM

public static final int CENNAM
另请参见:
常量字段值

CENEXT

public static final int CENEXT
另请参见:
常量字段值

CENCOM

public static final int CENCOM
另请参见:
常量字段值

CENDSK

public static final int CENDSK
另请参见:
常量字段值

CENATT

public static final int CENATT
另请参见:
常量字段值

CENATX

public static final int CENATX
另请参见:
常量字段值

CENOFF

public static final int CENOFF
另请参见:
常量字段值

ENDSUB

public static final int ENDSUB
另请参见:
常量字段值

ENDTOT

public static final int ENDTOT
另请参见:
常量字段值

ENDSIZ

public static final int ENDSIZ
另请参见:
常量字段值

ENDOFF

public static final int ENDOFF
另请参见:
常量字段值

ENDCOM

public static final int ENDCOM
另请参见:
常量字段值
构造方法详细信息

ZipFile

public ZipFile(String name)        throws IOException
打开 ZIP 文件进行阅读。

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

参数:
name - ZIP 文件的名称
抛出:
ZipException - 如果发生 ZIP 格式错误
IOException - 如果发生 I/O 错误
SecurityException - 如果存在安全管理器,并且其 checkRead 方法不允许对该文件进行阅读访问。
另请参见:
SecurityManager.checkRead(java.lang.String)

ZipFile

public ZipFile(File file,               int mode)        throws IOException
打开新的 ZipFile 以使用指定模式从指定 File 对象读取。模式参数必须为 OPEN_READOPEN_READ | OPEN_DELETE

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

参数:
file - 要打开进行阅读的 ZIP 文件
mode - 要用于打开文件的模式
抛出:
ZipException - 如果发生 ZIP 格式错误
IOException - 如果发生 I/O 错误
SecurityException - 如果存在安全管理器,并且其 checkRead 方法不允许对该文件进行读取访问,或者当设置了OPEN_DELETE 标志时,其 checkDelete 方法不允许删除该文件。
IllegalArgumentException - 如果 mode 参数无效
从以下版本开始:
1.3
另请参见:
SecurityManager.checkRead(java.lang.String)

ZipFile

public ZipFile(File file)        throws ZipException,               IOException
打开供阅读的 ZIP 文件,由指定的 File 对象给出。

参数:
file - 要打开供阅读的 ZIP 文件
抛出:
ZipException - 如果发生 ZIP 错误
IOException - 如果发生 I/O 错误
方法详细信息

getEntry

public ZipEntry getEntry(String name)
返回指定名称的 ZIP 文件条目;如果未找到,则返回 null。

参数:
name - 条目名称
返回:
ZIP 文件条目;如果未找到,则返回 null
抛出:
IllegalStateException - 如果已关闭该 ZIP

getInputStream

public InputStream getInputStream(ZipEntry entry)                           throws IOException
返回输入流以读取指定 ZIP 文件条目的内容。

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

参数:
entry - ZIP 文件条目
返回:
读取指定 ZIP 文件条目内容的输入流。
抛出:
ZipException - 如果发生 ZIP 格式错误
IOException - 如果发生 I/O 错误
IllegalStateException - 如果已关闭 ZIP 文件

getName

public String getName()
返回 ZIP 文件的路径名。

返回:
ZIP 文件的路径名

entries

public Enumeration<? extends ZipEntry> entries()
返回 ZIP 文件条目的枚举。

返回:
ZIP 文件条目的枚举
抛出:
IllegalStateException - 如果已关闭 ZIP 文件

size

public int size()
返回 ZIP 文件中的条目数。

返回:
ZIP 文件中的条目数
抛出:
IllegalStateException - 如果已关闭 ZIP 文件

close

public void close()           throws IOException
关闭 ZIP 文件。

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

抛出:
IOException - 如果发生 I/O 错误

finalize

protected void finalize()                 throws IOException
确保不再引用此 ZIP 文件时调用它的 close 方法。

由于不确定 GC 何时调用此方法,因此强烈建议应用程序一完成访问此 ZipFile 就调用 close 方法。这可防止不定期地保持系统资源。

覆盖:
Object 中的 finalize
抛出:
IOException - 如果发生 I/O 错误
另请参见:
close()
0 0