站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JDK 5 Documentation v1.2.2, Java 2 SDK 英文文档

Java(TM) 2 Platform, Standard Edition, v1.2.2 API Specification: Class ZipFile - JDK 5 Documentation v1.2.2, Java 2 SDK 英文文档

JavaTM 2 Platform
Standard Edition

java.util.zip
Class ZipFile

java.lang.Object
  |
  +--java.util.zip.ZipFile
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.


Fields inherited from interface java.util.zip.ZipConstants
CENATT, CENATX, CENCOM, CENCRC, CENDSK, CENEXT, CENFLG, CENHDR, CENHOW, CENLEN, CENNAM, CENOFF, CENSIG, CENSIZ, CENTIM, CENVEM, CENVER, ENDCOM, ENDHDR, ENDOFF, ENDSIG, ENDSIZ, ENDSUB, ENDTOT, EXTCRC, EXTHDR, EXTLEN, EXTSIG, EXTSIZ, LOCCRC, LOCEXT, LOCFLG, LOCHDR, LOCHOW, LOCLEN, LOCNAM, LOCSIG, LOCSIZ, LOCTIM, LOCVER
 
Constructor Summary
ZipFile(File file)
          Opens a ZIP file for reading given the specified File object.
ZipFile(String name)
          Opens a zip file for reading.
 
Method Summary
 void close()
          Closes the ZIP file.
 Enumeration entries()
          Returns an enumeration of the ZIP file entries.
 ZipEntry getEntry(String name)
          Returns the zip file entry for the specified name, or null if not found.
 InputStream getInputStream(ZipEntry entry)
          Returns an input stream for reading the contents of the specified zip file entry.
 String getName()
          Returns the path name of the ZIP file.
 int size()
          Returns the number of entries in the ZIP file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZipFile

public ZipFile(String name)
        throws IOException
Opens a zip file for reading.

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.

Parameters:
name - 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.
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.
Parameters:
file - the ZIP file to be opened for reading
Throws:
ZipException - if a ZIP error has occurred
IOException - if an I/O error has occurred
Method Detail

getEntry

public ZipEntry getEntry(String name)
Returns the zip file entry for the specified name, or null if not found.
Parameters:
name - the name of the entry
Returns:
the zip file entry, or null if not found
Throws:
IllegalStateException - if the zip file has been closed

getInputStream

public InputStream getInputStream(ZipEntry entry)
                           throws IOException
Returns an input stream for reading the contents of the specified zip file entry.
Parameters:
entry - the 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

getName

public String getName()
Returns the path name of the ZIP file.

entries

public Enumeration entries()
Returns an enumeration of the ZIP file entries.
Throws:
IllegalStateException - if the zip file has been closed

size

public int size()
Returns the number of entries in the ZIP file.
Throws:
IllegalStateException - if the zip file has been closed

close

public void close()
           throws IOException
Closes the ZIP file.

JavaTM 2 Platform
Standard Edition

Submit a bug or feature
Java, Java 2D, and JDBC are a trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.