java.util.zip
Class ZipFile

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.util.zip.ZipFile
Direct Known Subclasses:
JarFile sample code for java.util.jar.JarFile definition code for java.util.jar.JarFile

public class ZipFile
extends Object sample code for java.lang.Object definition code for java.lang.Object

This class is used to read entries from a zip file.

Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException to be thrown.


Field Summary
static int CENATT sample code for java.util.zip.ZipFile.CENATT definition code for java.util.zip.ZipFile.CENATT
           
static int CENATX sample code for java.util.zip.ZipFile.CENATX definition code for java.util.zip.ZipFile.CENATX
           
static int CENCOM sample code for java.util.zip.ZipFile.CENCOM definition code for java.util.zip.ZipFile.CENCOM
           
static int CENCRC sample code for java.util.zip.ZipFile.CENCRC definition code for java.util.zip.ZipFile.CENCRC
           
static int CENDSK sample code for java.util.zip.ZipFile.CENDSK definition code for java.util.zip.ZipFile.CENDSK
           
static int CENEXT sample code for java.util.zip.ZipFile.CENEXT definition code for java.util.zip.ZipFile.CENEXT
           
static int CENFLG sample code for java.util.zip.ZipFile.CENFLG definition code for java.util.zip.ZipFile.CENFLG
           
static int CENHDR sample code for java.util.zip.ZipFile.CENHDR definition code for java.util.zip.ZipFile.CENHDR
           
static int CENHOW sample code for java.util.zip.ZipFile.CENHOW definition code for java.util.zip.ZipFile.CENHOW
           
static int CENLEN sample code for java.util.zip.ZipFile.CENLEN definition code for java.util.zip.ZipFile.CENLEN
           
static int CENNAM sample code for java.util.zip.ZipFile.CENNAM definition code for java.util.zip.ZipFile.CENNAM
           
static int CENOFF sample code for java.util.zip.ZipFile.CENOFF definition code for java.util.zip.ZipFile.CENOFF
           
static long CENSIG sample code for java.util.zip.ZipFile.CENSIG definition code for java.util.zip.ZipFile.CENSIG
           
static int CENSIZ sample code for java.util.zip.ZipFile.CENSIZ definition code for java.util.zip.ZipFile.CENSIZ
           
static int CENTIM sample code for java.util.zip.ZipFile.CENTIM definition code for java.util.zip.ZipFile.CENTIM
           
static int CENVEM sample code for java.util.zip.ZipFile.CENVEM definition code for java.util.zip.ZipFile.CENVEM
           
static int CENVER sample code for java.util.zip.ZipFile.CENVER definition code for java.util.zip.ZipFile.CENVER
           
static int ENDCOM sample code for java.util.zip.ZipFile.ENDCOM definition code for java.util.zip.ZipFile.ENDCOM
           
static int ENDHDR sample code for java.util.zip.ZipFile.ENDHDR definition code for java.util.zip.ZipFile.ENDHDR
           
static int ENDOFF sample code for java.util.zip.ZipFile.ENDOFF definition code for java.util.zip.ZipFile.ENDOFF
           
static long ENDSIG sample code for java.util.zip.ZipFile.ENDSIG definition code for java.util.zip.ZipFile.ENDSIG
           
static int ENDSIZ sample code for java.util.zip.ZipFile.ENDSIZ definition code for java.util.zip.ZipFile.ENDSIZ
           
static int ENDSUB sample code for java.util.zip.ZipFile.ENDSUB definition code for java.util.zip.ZipFile.ENDSUB
           
static int ENDTOT sample code for java.util.zip.ZipFile.ENDTOT definition code for java.util.zip.ZipFile.ENDTOT
           
static int EXTCRC sample code for java.util.zip.ZipFile.EXTCRC definition code for java.util.zip.ZipFile.EXTCRC
           
static int EXTHDR sample code for java.util.zip.ZipFile.EXTHDR definition code for java.util.zip.ZipFile.EXTHDR
           
static int EXTLEN sample code for java.util.zip.ZipFile.EXTLEN definition code for java.util.zip.ZipFile.EXTLEN
           
static long EXTSIG sample code for java.util.zip.ZipFile.EXTSIG definition code for java.util.zip.ZipFile.EXTSIG
           
static int EXTSIZ sample code for java.util.zip.ZipFile.EXTSIZ definition code for java.util.zip.ZipFile.EXTSIZ
           
static int LOCCRC sample code for java.util.zip.ZipFile.LOCCRC definition code for java.util.zip.ZipFile.LOCCRC
           
static int LOCEXT sample code for java.util.zip.ZipFile.LOCEXT definition code for java.util.zip.ZipFile.LOCEXT
           
static int LOCFLG sample code for java.util.zip.ZipFile.LOCFLG definition code for java.util.zip.ZipFile.LOCFLG
           
static int LOCHDR sample code for java.util.zip.ZipFile.LOCHDR definition code for java.util.zip.ZipFile.LOCHDR
           
static int LOCHOW sample code for java.util.zip.ZipFile.LOCHOW definition code for java.util.zip.ZipFile.LOCHOW
           
static int LOCLEN sample code for java.util.zip.ZipFile.LOCLEN definition code for java.util.zip.ZipFile.LOCLEN
           
static int LOCNAM sample code for java.util.zip.ZipFile.LOCNAM definition code for java.util.zip.ZipFile.LOCNAM
           
static long LOCSIG sample code for java.util.zip.ZipFile.LOCSIG definition code for java.util.zip.ZipFile.LOCSIG
           
static int LOCSIZ sample code for java.util.zip.ZipFile.LOCSIZ definition code for java.util.zip.ZipFile.LOCSIZ
           
static int LOCTIM sample code for java.util.zip.ZipFile.LOCTIM definition code for java.util.zip.ZipFile.LOCTIM
           
static int LOCVER sample code for java.util.zip.ZipFile.LOCVER definition code for java.util.zip.ZipFile.LOCVER
           
static int OPEN_DELETE sample code for java.util.zip.ZipFile.OPEN_DELETE definition code for java.util.zip.ZipFile.OPEN_DELETE
          Mode flag to open a zip file and mark it for deletion.
static int OPEN_READ sample code for java.util.zip.ZipFile.OPEN_READ definition code for java.util.zip.ZipFile.OPEN_READ
          Mode flag to open a zip file for reading.
 
Constructor Summary
ZipFile sample code for java.util.zip.ZipFile.ZipFile(java.io.File) definition code for java.util.zip.ZipFile.ZipFile(java.io.File) (File sample code for java.io.File definition code for java.io.File  file)
          Opens a ZIP file for reading given the specified File object.
ZipFile sample code for java.util.zip.ZipFile.ZipFile(java.io.File, int) definition code for java.util.zip.ZipFile.ZipFile(java.io.File, int) (File sample code for java.io.File definition code for java.io.File  file, int mode)
          Opens a new ZipFile to read from the specified File object in the specified mode.
ZipFile sample code for java.util.zip.ZipFile.ZipFile(java.lang.String) definition code for java.util.zip.ZipFile.ZipFile(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  name)
          Opens a zip file for reading.
 
Method Summary
 void close sample code for java.util.zip.ZipFile.close() definition code for java.util.zip.ZipFile.close() ()
          Closes the ZIP file.
 Enumeration sample code for java.util.Enumeration definition code for java.util.Enumeration <? extends ZipEntry sample code for java.util.zip.ZipEntry definition code for java.util.zip.ZipEntry > entries sample code for java.util.zip.ZipFile.entries() definition code for java.util.zip.ZipFile.entries() ()
          Returns an enumeration of the ZIP file entries.
protected  void finalize sample code for java.util.zip.ZipFile.finalize() definition code for java.util.zip.ZipFile.finalize() ()
          Ensures that the close method of this ZIP file is called when there are no more references to it.
 ZipEntry sample code for java.util.zip.ZipEntry definition code for java.util.zip.ZipEntry getEntry sample code for java.util.zip.ZipFile.getEntry(java.lang.String) definition code for java.util.zip.ZipFile.getEntry(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  name)
          Returns the zip file entry for the specified name, or null if not found.
 InputStream sample code for java.io.InputStream definition code for java.io.InputStream getInputStream sample code for java.util.zip.ZipFile.getInputStream(java.util.zip.ZipEntry) definition code for java.util.zip.ZipFile.getInputStream(java.util.zip.ZipEntry) (ZipEntry sample code for java.util.zip.ZipEntry definition code for java.util.zip.ZipEntry  entry)
          Returns an input stream for reading the contents of the specified zip file entry.
 String sample code for java.lang.String definition code for java.lang.String getName sample code for java.util.zip.ZipFile.getName() definition code for java.util.zip.ZipFile.getName() ()
          Returns the path name of the ZIP file.
 int size sample code for java.util.zip.ZipFile.size() definition code for java.util.zip.ZipFile.size() ()
          Returns the number of entries in the ZIP file.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

OPEN_READ sample code for java.util.zip.ZipFile.OPEN_READ

public static final int OPEN_READ
Mode flag to open a zip file for reading.

See Also:
Constant Field Values

OPEN_DELETE sample code for java.util.zip.ZipFile.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.

See Also:
Constant Field Values

LOCSIG sample code for java.util.zip.ZipConstants.LOCSIG

public static final long LOCSIG
See Also:
Constant Field Values

EXTSIG sample code for java.util.zip.ZipConstants.EXTSIG

public static final long EXTSIG
See Also:
Constant Field Values

CENSIG sample code for java.util.zip.ZipConstants.CENSIG

public static final long CENSIG
See Also:
Constant Field Values

ENDSIG sample code for java.util.zip.ZipConstants.ENDSIG

public static final long ENDSIG
See Also:
Constant Field Values

LOCHDR sample code for java.util.zip.ZipConstants.LOCHDR

public static final int LOCHDR
See Also:
Constant Field Values

EXTHDR sample code for java.util.zip.ZipConstants.EXTHDR

public static final int EXTHDR
See Also:
Constant Field Values

CENHDR sample code for java.util.zip.ZipConstants.CENHDR

public static final int CENHDR
See Also:
Constant Field Values

ENDHDR sample code for java.util.zip.ZipConstants.ENDHDR

public static final int ENDHDR
See Also:
Constant Field Values

LOCVER sample code for java.util.zip.ZipConstants.LOCVER

public static final int LOCVER
See Also:
Constant Field Values

LOCFLG sample code for java.util.zip.ZipConstants.LOCFLG

public static final int LOCFLG
See Also:
Constant Field Values

LOCHOW sample code for java.util.zip.ZipConstants.LOCHOW

public static final int LOCHOW
See Also:
Constant Field Values

LOCTIM sample code for java.util.zip.ZipConstants.LOCTIM

public static final int LOCTIM
See Also:
Constant Field Values

LOCCRC sample code for java.util.zip.ZipConstants.LOCCRC

public static final int LOCCRC
See Also:
Constant Field Values

LOCSIZ sample code for java.util.zip.ZipConstants.LOCSIZ

public static final int LOCSIZ
See Also:
Constant Field Values

LOCLEN sample code for java.util.zip.ZipConstants.LOCLEN

public static final int LOCLEN
See Also:
Constant Field Values

LOCNAM sample code for java.util.zip.ZipConstants.LOCNAM

public static final int LOCNAM
See Also:
Constant Field Values

LOCEXT sample code for java.util.zip.ZipConstants.LOCEXT

public static final int LOCEXT
See Also:
Constant Field Values

EXTCRC sample code for java.util.zip.ZipConstants.EXTCRC

public static final int EXTCRC
See Also:
Constant Field Values

EXTSIZ sample code for java.util.zip.ZipConstants.EXTSIZ

public static final int EXTSIZ
See Also:
Constant Field Values

EXTLEN sample code for java.util.zip.ZipConstants.EXTLEN

public static final int EXTLEN
See Also:
Constant Field Values

CENVEM sample code for java.util.zip.ZipConstants.CENVEM

public static final int CENVEM
See Also:
Constant Field Values

CENVER sample code for java.util.zip.ZipConstants.CENVER

public static final int CENVER
See Also:
Constant Field Values

CENFLG sample code for java.util.zip.ZipConstants.CENFLG

public static final int CENFLG
See Also:
Constant Field Values

CENHOW sample code for java.util.zip.ZipConstants.CENHOW

public static final int CENHOW
See Also:
Constant Field Values

CENTIM sample code for java.util.zip.ZipConstants.CENTIM

public static final int CENTIM
See Also:
Constant Field Values

CENCRC sample code for java.util.zip.ZipConstants.CENCRC

public static final int CENCRC
See Also:
Constant Field Values

CENSIZ sample code for java.util.zip.ZipConstants.CENSIZ

public static final int CENSIZ
See Also:
Constant Field Values

CENLEN sample code for java.util.zip.ZipConstants.CENLEN

public static final int CENLEN
See Also:
Constant Field Values

CENNAM sample code for java.util.zip.ZipConstants.CENNAM

public static final int CENNAM
See Also:
Constant Field Values

CENEXT sample code for java.util.zip.ZipConstants.CENEXT

public static final int CENEXT
See Also:
Constant Field Values

CENCOM sample code for java.util.zip.ZipConstants.CENCOM

public static final int CENCOM
See Also:
Constant Field Values

CENDSK sample code for java.util.zip.ZipConstants.CENDSK

public static final int CENDSK
See Also:
Constant Field Values

CENATT sample code for java.util.zip.ZipConstants.CENATT

public static final int CENATT
See Also:
Constant Field Values

CENATX sample code for java.util.zip.ZipConstants.CENATX

public static final int CENATX
See Also:
Constant Field Values

CENOFF sample code for java.util.zip.ZipConstants.CENOFF

public static final int CENOFF
See Also:
Constant Field Values

ENDSUB sample code for java.util.zip.ZipConstants.ENDSUB

public static final int ENDSUB
See Also:
Constant Field Values

ENDTOT sample code for java.util.zip.ZipConstants.ENDTOT

public static final int ENDTOT
See Also:
Constant Field Values

ENDSIZ sample code for java.util.zip.ZipConstants.ENDSIZ

public static final int ENDSIZ
See Also:
Constant Field Values

ENDOFF sample code for java.util.zip.ZipConstants.ENDOFF

public static final int ENDOFF
See Also:
Constant Field Values

ENDCOM sample code for java.util.zip.ZipConstants.ENDCOM

public static final int ENDCOM
See Also:
Constant Field Values
Constructor Detail

ZipFile sample code for java.util.zip.ZipFile(java.lang.String) definition code for java.util.zip.ZipFile(java.lang.String)

public ZipFile(String sample code for java.lang.String definition code for java.lang.String  name)
        throws IOException sample code for java.io.IOException definition code for java.io.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 sample code for java.util.zip.ZipException definition code for java.util.zip.ZipException - if a ZIP format error has occurred
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error has occurred
SecurityException sample code for java.lang.SecurityException definition code for java.lang.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) sample code for java.lang.SecurityManager.checkRead(java.lang.String) definition code for java.lang.SecurityManager.checkRead(java.lang.String)

ZipFile sample code for java.util.zip.ZipFile(java.io.File, int) definition code for java.util.zip.ZipFile(java.io.File, int)

public ZipFile(File sample code for java.io.File definition code for java.io.File  file,
               int mode)
        throws IOException sample code for java.io.IOException definition code for java.io.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.

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:
file - the ZIP file to be opened for reading
mode - the mode in which the file is to be opened
Throws:
ZipException sample code for java.util.zip.ZipException definition code for java.util.zip.ZipException - if a ZIP format error has occurred
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error has occurred
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkRead method doesn't allow read access to the file, or its checkDelete method doesn't allow deleting the file when the OPEN_DELETE flag is set.
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the mode argument is invalid
See Also:
SecurityManager.checkRead(java.lang.String) sample code for java.lang.SecurityManager.checkRead(java.lang.String) definition code for java.lang.SecurityManager.checkRead(java.lang.String)

ZipFile sample code for java.util.zip.ZipFile(java.io.File) definition code for java.util.zip.ZipFile(java.io.File)

public ZipFile(File sample code for java.io.File definition code for java.io.File  file)
        throws ZipException sample code for java.util.zip.ZipException definition code for java.util.zip.ZipException ,
               IOException sample code for java.io.IOException definition code for java.io.IOException 
Opens a ZIP file for reading given the specified File object.

Parameters:
file - the ZIP file to be opened for reading
Throws:
ZipException sample code for java.util.zip.ZipException definition code for java.util.zip.ZipException - if a ZIP error has occurred
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error has occurred
Method Detail

getEntry sample code for java.util.zip.ZipFile.getEntry(java.lang.String) definition code for java.util.zip.ZipFile.getEntry(java.lang.String)

public ZipEntry sample code for java.util.zip.ZipEntry definition code for java.util.zip.ZipEntry  getEntry(String sample code for java.lang.String definition code for java.lang.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 sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if the zip file has been closed

getInputStream sample code for java.util.zip.ZipFile.getInputStream(java.util.zip.ZipEntry) definition code for java.util.zip.ZipFile.getInputStream(java.util.zip.ZipEntry)

public InputStream sample code for java.io.InputStream definition code for java.io.InputStream  getInputStream(ZipEntry sample code for java.util.zip.ZipEntry definition code for java.util.zip.ZipEntry  entry)
                           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Returns an input stream for reading the contents of the specified zip file entry. Returns an input stream for reading the contents of the specified zip file entry.

Closing this ZIP file will, in turn, close all input streams that have been returned by invocations of this method.

Parameters:
entry - the zip file entry
Returns:
the input stream for reading the contents of the specified zip file entry.
Throws:
ZipException sample code for java.util.zip.ZipException definition code for java.util.zip.ZipException - if a ZIP format error has occurred
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error has occurred
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if the zip file has been closed

getName sample code for java.util.zip.ZipFile.getName() definition code for java.util.zip.ZipFile.getName()

public String sample code for java.lang.String definition code for java.lang.String  getName()
Returns the path name of the ZIP file.

Returns:
the path name of the ZIP file

entries sample code for java.util.zip.ZipFile.entries() definition code for java.util.zip.ZipFile.entries()

public Enumeration sample code for java.util.Enumeration definition code for java.util.Enumeration <? extends ZipEntry sample code for java.util.zip.ZipEntry definition code for java.util.zip.ZipEntry > entries()
Returns an enumeration of the ZIP file entries.

Returns:
an enumeration of the ZIP file entries
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if the zip file has been closed

size sample code for java.util.zip.ZipFile.size() definition code for java.util.zip.ZipFile.size()

public int size()
Returns the number of entries in the ZIP file.

Returns:
the number of entries in the ZIP file
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if the zip file has been closed

close sample code for java.util.zip.ZipFile.close() definition code for java.util.zip.ZipFile.close()

public void close()
           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Closes the ZIP file.

Closing this ZIP file will close all of the input streams previously returned by invocations of the getInputStream sample code for java.util.zip.ZipFile.getInputStream(java.util.zip.ZipEntry) definition code for java.util.zip.ZipFile.getInputStream(java.util.zip.ZipEntry) method.

Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error has occurred

finalize sample code for java.util.zip.ZipFile.finalize() definition code for java.util.zip.ZipFile.finalize()

protected void finalize()
                 throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Ensures that the close method of this ZIP file is called when there are no more references to it.

Since the time when GC would invoke this method is undetermined, it is strongly recommended 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.

Overrides:
finalize