to top
Android APIs
public class

JarFile

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

Class Overview

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

Summary

Constants
String MANIFEST_NAME The MANIFEST file name.
[Expand]
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.
[Expand]
Inherited Methods
From class java.util.zip.ZipFile
From class java.lang.Object

Constants

public static final String MANIFEST_NAME

Since: API Level 1

The MANIFEST file name.

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

Public Constructors

public JarFile (File file)

Since: API Level 1

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

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

public JarFile (File file, boolean verify)

Since: API Level 1

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

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

public JarFile (File file, boolean verify, int mode)

Since: API Level 1

Create a new JarFile using the contents of file.

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

public JarFile (String filename)

Since: API Level 1

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

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

public JarFile (String filename, boolean verify)

Since: API Level 1

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

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

Public Methods

public void close ()

Since: API Level 1

Closes this JarFile.

Throws
IOException if an error occurs.

public Enumeration<JarEntry> entries ()

Since: API Level 1

Return an enumeration containing the JarEntrys contained in this JarFile.

Returns
  • the Enumeration containing the JAR entries.
Throws
IllegalStateException if this JarFile is closed.

public ZipEntry getEntry (String name)

Since: API Level 1

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

Parameters
name the name of the entry in the JAR file.
Returns
  • the ZIP entry extracted.

public InputStream getInputStream (ZipEntry ze)

Since: API Level 1

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

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

public JarEntry getJarEntry (String name)

Since: API Level 1

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

Parameters
name the name of the entry in the JAR file.
Returns
  • the JAR entry defined by the name.

public Manifest getManifest ()

Since: API Level 1

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

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