| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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 | |
---|---|
Opens a ZIP file for reading given the specified File object. |
|
Opens a new ZipFile to read from the specified
File object in the specified mode.
|
|
Opens a zip file for reading. |
Method Summary | |
---|---|
void |
close() Closes the ZIP file. |
Enumeration |
entries() Returns an enumeration of the ZIP file entries. |
protected void |
finalize() 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 |
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 |
Field Detail |
---|
public static final int OPEN_DELETE
public static final int OPEN_READ
Constructor Detail |
---|
public ZipFile(File file) throws ZipException, IOException
file
- the ZIP file to be opened for readingZipException
- if a ZIP error has occurredIOException
- if an I/O error has occurredpublic ZipFile(File file, int mode) throws IOException
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.
file
- the ZIP file to be opened for readingmode
- the mode in which the file is to be openedIOException
- if an I/O error has occurredpublic ZipFile(String name) throws IOException
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.
name
- the name of the zip fileIOException
- if an I/O error has occurredMethod Detail |
---|
public void close() throws IOException
Closing this ZIP file will close all of the input streams previously returned by invocations of the {@link #getInputStream getInputStream} method.
IOException
- if an I/O error has occurredpublic Enumeration entries()
protected void finalize() throws IOException
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.
finalize
in class Object
IOException
- if an I/O error has occurredpublic ZipEntry getEntry(String name)
name
- the name of the entrypublic InputStream getInputStream(ZipEntry entry) throws IOException
Closing this ZIP file will, in turn, close all input streams that have been returned by invocations of this method.
entry
- the zip file entryIOException
- if an I/O error has occurredpublic String getName()
public int size()
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |