The jar Tool

Sun's JDK contains a simple command-line program called jar that packages a set of files or a directory structure into a JAR file. Its syntax is modeled after the Unix tar command. For instance, to verbosely compress the directory com into the file javaio.jar with the manifest file, you would type the following command line:

% jar cvmf javaio.jar com
added manifest
adding: com/ (in=0) (out=0) (stored 0%)
xsadding: com/elharo/ (in=0) (out=0) (stored 0%)
adding: com/elharo/io/ (in=0) (out=0) (stored 0%)
adding: com/elharo/io/StreamCopier.class (in=887) (out=552) (deflated 37%)
adding: com/elharo/io/NullOutputStream.class (in=374) (out=225) (deflated 39%)
adding: com/elharo/io/RandomInputStream.class (in=792) (out=487) (deflated 38%)
adding: com/elharo/io/ (in=263) (out=149) (deflated 43%)
adding: com/elharo/io/ (in=764) (out=377) (deflated 50%)

This creates a file named javaio.jar. To extract files, change cvmf (c reate v erbose with m anifest f ile) to xvf (ex tract v erbose f ile). If you don't care to see each file as it's added or extracted, you can omit the v argument:

% jar xf javaio.jar

You can also use any other zip tool to create or unpack JAR archives. However, you'll have to include the META-INF/MANIFEST.MF file manually.

The JDK also includes a jarsigner tool that digitally signs JAR archives and verifies JAR archives signed by others using a public key system.

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: