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
。
Constants |
|
---|---|
String |
MANIFEST_NAME JAR清单文件名称。 |
Inherited constants |
---|
From class java.util.zip.ZipFile
|
Public constructors |
|
---|---|
JarFile(String name) 创建一个新的 |
|
JarFile(String name, boolean verify) 创建一个新的 |
|
JarFile(File file) 创建一个新的 |
|
JarFile(File file, boolean verify) 创建一个新的 |
|
JarFile(File file, boolean verify, int mode) 创建一个新的 |
Public methods |
|
---|---|
Enumeration<JarEntry> |
entries() 返回压缩文件条目的枚举。 |
ZipEntry |
getEntry(String name) 返回 |
InputStream |
getInputStream(ZipEntry ze) 返回用于读取指定zip文件条目内容的输入流。 |
JarEntry |
getJarEntry(String name) 如果未找到,则返回给定条目名称的 |
Manifest |
getManifest() 返回jar文件清单,如果没有,则返回 |
Inherited methods |
|
---|---|
From class java.util.zip.ZipFile
|
|
From class java.lang.Object
|
|
From interface java.io.Closeable
|
|
From interface java.lang.AutoCloseable
|
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 (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 (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 (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 (File file, boolean verify, int mode)
创建一个新的JarFile
以从指定模式下的指定File
对象读取。 模式参数必须是OPEN_READ或OPEN_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 |
Enumeration<JarEntry> entries ()
返回压缩文件条目的枚举。
Returns | |
---|---|
Enumeration<JarEntry> |
an enumeration of the ZIP file entries |
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 |
也可以看看:
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 |
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 |
也可以看看:
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 |