java.util.zip
类 ZipFile
java.lang.Objectjava.util.zip.ZipFile
- 直接已知子类:
- JarFile
public class ZipFileextends Object
此类用于从 ZIP 文件读取条目。
除非另有说明,将 null 参数传入此类中的构造方法或方法将导致抛出 NullPointerException。
| 字段摘要 | |
|---|---|
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打开 ZIP 文件并将其标记为删除的模式标志。 |
static int | OPEN_READ打开 ZIP 文件进行阅读的模式标志。 |
| 构造方法摘要 | |
|---|---|
ZipFile(File file)打开供阅读的 ZIP 文件,由指定的 File 对象给出。 | |
ZipFile(File file, int mode)打开新的 ZipFile 以使用指定模式从指定 File 对象读取。 | |
ZipFile(String name)打开 ZIP 文件进行阅读。 | |
| 方法摘要 | |
|---|---|
void | close()关闭 ZIP 文件。 |
Enumeration<? extends ZipEntry> | entries()返回 ZIP 文件条目的枚举。 |
protected void | finalize()确保不再引用此 ZIP 文件时调用它的 close 方法。 |
ZipEntry | getEntry(String name)返回指定名称的 ZIP 文件条目;如果未找到,则返回 null。 |
InputStream | getInputStream(ZipEntry entry)返回输入流以读取指定 ZIP 文件条目的内容。 |
String | getName()返回 ZIP 文件的路径名。 |
int | size()返回 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_READ 或 OPEN_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()
本文介绍了 Java 中 ZipFile 类的基本用法,包括如何创建 ZipFile 对象以读取 ZIP 文件,以及通过 ZipFile 访问 ZIP 文件条目的方法。文章还列举了 ZipFile 类中的常用静态字段和方法。
java.util.zip.ZipFile
326

被折叠的 条评论
为什么被折叠?



