This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


java.util.zip
class ZipFile

java.lang.Object extended by java.util.zip.ZipFile
All Implemented Interfaces:
ZipConstants
Direct Known Subclasses:
JarFile

Most common way to construct:

String filename = …;

ZipFile zf = new ZipFile(filename);

Based on 21 examples


public class ZipFile
extends Object
implements ZipConstants

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 {@link NullPointerException} to be thrown.


Field Summary
static int OPEN_DELETE
          Mode flag to open a zip file and mark it for deletion.
static int OPEN_READ
          Mode flag to open a zip file for reading.
 
Constructor Summary
ZipFile(File file)

          Opens a ZIP file for reading given the specified File object.
ZipFile(File file, int mode)

          Opens a new ZipFile to read from the specified File object in the specified mode.

          Opens a zip file for reading.
 
Method Summary
 void

          Closes the ZIP file.
 Enumeration

          Returns an enumeration of the ZIP file entries.
protected void

          Ensures that the close method of this ZIP file is called when there are no more references to it.
 ZipEntry

          Returns the zip file entry for the specified name, or null if not found.
 InputStream

          Returns an input stream for reading the contents of the specified zip file entry.
 String

          Returns the path name of the ZIP file.
 int

          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
 

Field Detail

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.

OPEN_READ

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

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

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.

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:
IOException - if an I/O error has occurred

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:
IOException - if an I/O error has occurred
Method Detail

close

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

Closing this ZIP file will close all of the input streams previously returned by invocations of the {@link #getInputStream getInputStream} method.

Throws:
IOException - if an I/O error has occurred

entries

public Enumeration entries()
Returns an enumeration of the ZIP file entries.

Returns:
an enumeration of the ZIP file entries

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.

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 in class Object
Throws:
IOException - if an I/O error has occurred

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

getInputStream

public InputStream getInputStream(ZipEntry entry)
                           throws IOException
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:
IOException - if an I/O error has occurred

getName

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

Returns:
the path name of the ZIP file

size

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

Returns:
the number of entries in the ZIP file


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.