Most visited

Recently visited

Added in API level 1

JarFile

public class JarFile
extends ZipFile

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


JarFile类用于从任何可以使用java.io.RandomAccessFile打开的文件中读取jar文件的内容。 它扩展了类java.util.zip.ZipFile ,支持读取可选的Manifest条目。 Manifest可用于指定有关jar文件及其条目的元信息。

除非另有说明,否则将 null参数传递给 此类中的构造函数或方法将导致引发 NullPointerException

也可以看看:

Summary

Constants

String MANIFEST_NAME

JAR清单文件名称。

Inherited constants

From class java.util.zip.ZipFile

Public constructors

JarFile(String name)

创建一个新的 JarFile以从指定文件 name

JarFile(String name, boolean verify)

创建一个新的 JarFile以从指定的文件 name

JarFile(File file)

创建一个新的 JarFile以从指定的 File对象读取。

JarFile(File file, boolean verify)

创建一个新的 JarFile以从指定的 File对象读取。

JarFile(File file, boolean verify, int mode)

创建一个新的 JarFile以从指定模式下的指定 File对象读取。

Public methods

Enumeration<JarEntry> entries()

返回压缩文件条目的枚举。

ZipEntry getEntry(String name)

返回 ZipEntry给定条目名称或 null如果没有找到。

InputStream getInputStream(ZipEntry ze)

返回用于读取指定zip文件条目内容的输入流。

JarEntry getJarEntry(String name)

如果未找到,则返回给定条目名称的 null或返回 JarEntry

Manifest getManifest()

返回jar文件清单,如果没有,则返回 null

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

JAR清单文件名称。

常量值:“META-INF / MANIFEST.MF”

Public constructors

JarFile

Added in API level 1
JarFile (String name)

创建一个新的JarFile以从指定的文件name JarFile将被验证,如果它已签名。

Parameters
name String: the name of the jar file to be opened for reading
Throws
IOException if an I/O error has occurred
SecurityException if access to the file is denied by the SecurityManager

JarFile

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

创建一个新的 JarFile以从指定的文件 name

Parameters
name String: the name of the jar file to be opened for reading
verify boolean: whether or not to verify the jar file if it is signed.
Throws
IOException if an I/O error has occurred
SecurityException if access to the file is denied by the SecurityManager

JarFile

Added in API level 1
JarFile (File file)

创建一个新的JarFile以从指定的File对象读取。 JarFile将被验证,如果它已签名。

Parameters
file File: the jar file to be opened for reading
Throws
IOException if an I/O error has occurred
SecurityException if access to the file is denied by the SecurityManager

JarFile

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

创建一个新的 JarFile以从指定的 File对象读取。

Parameters
file File: the jar file to be opened for reading
verify boolean: whether or not to verify the jar file if it is signed.
Throws
IOException if an I/O error has occurred
SecurityException if access to the file is denied by the SecurityManager.

JarFile

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

创建一个新的JarFile以从指定模式下的指定File对象读取。 模式参数必须是OPEN_READOPEN_READ | OPEN_DELETE

Parameters
file File: the jar file to be opened for reading
verify boolean: whether or not to verify the jar file if it is signed.
mode int: the mode in which the file is to be opened
Throws
IOException if an I/O error has occurred
IllegalArgumentException if the mode argument is invalid
SecurityException if access to the file is denied by the SecurityManager

Public methods

entries

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

返回压缩文件条目的枚举。

Returns
Enumeration<JarEntry> an enumeration of the ZIP file entries

getEntry

Added in API level 1
ZipEntry getEntry (String name)

返回 ZipEntry给定条目名称或 null如果没有找到。

Parameters
name String: the jar file entry name
Returns
ZipEntry the ZipEntry for the given entry name or null if not found
Throws
IllegalStateException may be thrown if the jar file has been closed

也可以看看:

getInputStream

Added in API level 1
InputStream getInputStream (ZipEntry ze)

返回用于读取指定zip文件条目内容的输入流。

Parameters
ze ZipEntry: the zip file entry
Returns
InputStream an input stream for reading the contents of the specified zip file entry
Throws
ZipException if a zip file format error has occurred
IOException if an I/O error has occurred
SecurityException if any of the jar file entries are incorrectly signed.
IllegalStateException may be thrown if the jar file has been closed

getJarEntry

Added in API level 1
JarEntry getJarEntry (String name)

如果未找到,则返回给定条目名称的 null或返回 JarEntry

Parameters
name String: the jar file entry name
Returns
JarEntry the JarEntry for the given entry name or null if not found.
Throws
IllegalStateException may be thrown if the jar file has been closed

也可以看看:

getManifest

Added in API level 1
Manifest getManifest ()

返回jar文件清单,如果没有,则返回 null

Returns
Manifest the jar file manifest, or null if none
Throws
IllegalStateException may be thrown if the jar file has been closed
IOException

Hooray!