The java.util.jar Package

The java.util.jar package, shown in Figure 11-1, contains two stream classes and another half dozen assorted classes and interfaces that assist in reading from and writing to JAR archives. As you can see, almost everything in this package is a subclass of a related class in the package. JAR files are zip files, and they are read and written just like zip files. This package mostly adds support for reading and writing manifests. You don't have to use the java.util.jar package at and the standard I/O and string classes are enough to do anything you need to dobut java.util.jar certainly does make your job easier when you need to read manifest entries.

Figure 11-1. The java.util.jar package hierarchy

All of the classes in java.util.jar are used much like their superclasses are. For instance, to read a JAR file, follow these steps:

  1. Construct a JarInputStream object from an underlying stream, most commonly a file input stream.
  2. Open the next JAR entry in the archive.
  3. Read data from the JAR entry using InputStream methods such as read( ).
  4. Close the JAR entry (optional).
  5. Repeat steps 2 through 4 as long as there are more entries (files) remaining in the archive.
  6. Close the JAR input stream.

These are the same six steps you use to read a zip file, only with the classes replaced by their counterparts in java.util.jar.

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



Nonblocking I/O

The File System

Working with Files

File Dialogs and Choosers


Character Sets and Unicode

Readers and Writers

Formatted I/O with java.text


The Java Communications API


The J2ME Generic Connection Framework


Character Sets

Java I/O
Java I/O
ISBN: 0596527500
EAN: 2147483647
Year: 2004
Pages: 244 © 2008-2020.
If you may any questions please contact us: