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 |
|---|
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) |
|
|---|---|
java.util.zip.ZipFile
|
|
java.lang.Object
|
|
java.io.Closeable
|
|
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 |
|