JarFile

The java.util.jar.JarFile class represents a file in the JAR format. It is a subclass of java.util.zip.ZipFile, and JarFile objects are almost exactly like ZipFile objects.

public class JarFile extends ZipFile

The JarFile class has five constructors:

public JarFile(String filename) throws IOException
public JarFile(String filename, boolean verify) throws IOException
public JarFile(String filename, boolean verify, int mode) throws IOException
public JarFile(File file) throws IOException
public JarFile(File file, boolean verify) throws IOException

The first argument specifies the file to read, either by name or with a java.io.File object. The optional second argument, verify, is important only for signed JAR files. If verify is true, signatures will be checked against the file's contents; if verify is false, signatures will not be checked against the file's contents. The default is to check signatures. An IOException is thrown if an entry does not match its signature. The optional third argument, mode, should be one of the named constants ZipFile.OPEN_READ or ZipFile.OPEN_DELETE, to indicate whether the file is opened in read-only or read-and-delete mode. JAR files cannot be opened for writing.

The JarFile class is so similar in interface and behavior to java.util.zip.ZipFile that I can spare you a lot of details about most of its methods. It declares only the following five methods (though of course you shouldn't forget about the others it inherits from its superclass):

public ZipEntry getEntry(String name)
public Enumeration entries( )
public InputStream getInputStream(ZipEntry ze) throws IOException
public JarEntry getJarEntry(String name)
public Manifest getManifest( ) throws IOException

getEntry( ), enTRies( ), and getInputStream( ) are used exactly as they are for zip files. getJarEntry( ) is used almost exactly like getEntry( ), except that it's declared to return an instance of JarEntry, a subclass of ZipEntry. Some extra work takes place in these methods to read the manifest file and verify signatures, but unless the signatures don't verify (in which case an IOException is thrown), none of this is relevant to the client programmer. The one really interesting new method in this list is getManifest( ), which returns an instance of the java.util.jar.Manifest class. You can use this to read the entries in the manifest file, as described in the section on the Manifest class later in this chapter.

Basic I/O

Introducing I/O

Output Streams

Input Streams

Data Sources

File Streams

Network Streams

Filter Streams

Filter Streams

Print Streams

Data Streams

Streams in Memory

Compressing Streams

JAR Archives

Cryptographic Streams

Object Serialization

New I/O

Buffers

Channels

Nonblocking I/O

The File System

Working with Files

File Dialogs and Choosers

Text

Character Sets and Unicode

Readers and Writers

Formatted I/O with java.text

Devices

The Java Communications API

USB

The J2ME Generic Connection Framework

Bluetooth

Character Sets



Java I/O
Java I/O
ISBN: 0596527500
EAN: 2147483647
Year: 2004
Pages: 244

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net