Skip to content

Most visited

Recently visited

navigation
Added in API level 1

JarFile

public class JarFile
extends ZipFile

java.lang.Object
   ↳ java.util.zip.ZipFile
     ↳ java.util.jar.JarFile


JarFile is used to read jar entries and their associated data from jar files.

See also:

Summary

Constants

String MANIFEST_NAME

The MANIFEST file name.

Inherited constants

From class java.util.zip.ZipFile

Public constructors

JarFile(File file)

Create a new JarFile using the contents of the specified file.

JarFile(File file, boolean verify)

Create a new JarFile using the contents of the specified file.

JarFile(File file, boolean verify, int mode)

Create a new JarFile using the contents of file.

JarFile(String filename)

Create a new JarFile from the contents of the file specified by filename.

JarFile(String filename, boolean verify)

Create a new JarFile from the contents of the file specified by filename.

Public methods

void close()

Closes this JarFile.

Enumeration<JarEntry> entries()

Return an enumeration containing the JarEntrys contained in this JarFile.

ZipEntry getEntry(String name)

Return the JarEntry specified by name or null if no such entry exists.

InputStream getInputStream(ZipEntry ze)

Return an InputStream for reading the decompressed contents of ZIP entry.

JarEntry getJarEntry(String name)

Return the JarEntry specified by its name or null if no such entry exists.

Manifest getManifest()

Returns the Manifest object associated with this JarFile or null if no MANIFEST entry exists.

Inherited methods

From class java.util.zip.ZipFile
From class java.lang.Object
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Constants

MANIFEST_NAME

Added in API level 1
String MANIFEST_NAME

The MANIFEST file name.

Constant Value: "META-INF/MANIFEST.MF"

Public constructors

JarFile

Added in API level 1
JarFile (File file)

Create a new JarFile using the contents of the specified file.

Parameters
file File: the JAR file as File.
Throws
IOException If the file cannot be read.

JarFile

Added in API level 1
JarFile (File file, 
                boolean verify)

Create a new JarFile using the contents of the specified file.

Parameters
file File: the JAR file as File.
verify boolean: if this JAR file is signed whether it must be verified.
Throws
IOException If the file cannot be read.

JarFile

Added in API level 1
JarFile (File file, 
                boolean verify, 
                int mode)

Create a new JarFile using the contents of file.

Parameters
file File: the JAR file as File.
verify boolean: if this JAR filed is signed whether it must be verified.
mode int: the mode to use, either OPEN_READ or OPEN_DELETE.
Throws
IOException If the file cannot be read.

JarFile

Added in API level 1
JarFile (String filename)

Create a new JarFile from the contents of the file specified by filename.

Parameters
filename String: the file name referring to the JAR file.
Throws
IOException if file name cannot be opened for reading.

JarFile

Added in API level 1
JarFile (String filename, 
                boolean verify)

Create a new JarFile from the contents of the file specified by filename.

Parameters
filename String: the file name referring to the JAR file.
verify boolean: if this JAR filed is signed whether it must be verified.
Throws
IOException If file cannot be opened or read.

Public methods

close

Added in API level 1
void close ()

Closes this JarFile.

Throws
IOException if an error occurs.

entries

Added in API level 1
Enumeration<JarEntry> entries ()

Return an enumeration containing the JarEntrys contained in this JarFile.

Returns
Enumeration<JarEntry> the Enumeration containing the JAR entries.
Throws
IllegalStateException if this JarFile is closed.

getEntry

Added in API level 1
ZipEntry getEntry (String name)

Return the JarEntry specified by name or null if no such entry exists.

Parameters
name String: the name of the entry in the JAR file.
Returns
ZipEntry the ZIP entry extracted.

getInputStream

Added in API level 1
InputStream getInputStream (ZipEntry ze)

Return an InputStream for reading the decompressed contents of ZIP entry.

Parameters
ze ZipEntry: the ZIP entry to be read.
Returns
InputStream the input stream to read from.
Throws
IOException if an error occurred while creating the input stream.

getJarEntry

Added in API level 1
JarEntry getJarEntry (String name)

Return the JarEntry specified by its name or null if no such entry exists.

Parameters
name String: the name of the entry in the JAR file.
Returns
JarEntry the JAR entry defined by the name.

getManifest

Added in API level 1
Manifest getManifest ()

Returns the Manifest object associated with this JarFile or null if no MANIFEST entry exists.

Returns
Manifest the MANIFEST.
Throws
IOException if an error occurs reading the MANIFEST file.
IllegalStateException if the jar file is closed.

See also:

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.