读取 JAR 文件的内容(在运行时)? [英] Reading content of a JAR file (at runtime)?

查看:36
本文介绍了读取 JAR 文件的内容(在运行时)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读帖子:

查看 .jar 文件的内容

如何列出 JAR 文件中的文件?

但遗憾的是,我找不到一个好的解决方案来实际读取 JAR 的内容(逐个文件).

But I, sadly, couldn't find a good solution to actually read a JAR's content (file by file).

此外,有人可以给我一个提示,或指向一个资源,讨论我的问题吗?

Furthermore, could someone give me a hint, or point to a resource, where my problem is discussed?

我只是想出一种不那么直接的方法来做到这一点:
我可以以某种方式将 JAR 的资源列表转换为内部 JAR URL,然后我可以使用 openConnection() 打开它们.

推荐答案

您使用 JarFile 打开 Jar 文件.有了它,您可以通过使用getEntry(String name)"或entires"来获得 ZipEntry 或 JarEntry(它们可以被视为相同的东西).获得 Entry 后,您可以使用它通过调用 'JarFile.getInputStream(ZipEntry ze)'.那么你可以从流中读取数据.

You use JarFile to open a Jar file. With it you can get ZipEntry or JarEntry (they can be seen as the same thing) by using 'getEntry(String name)' or 'entires'. Once you get an Entry, you can use it to get InputStream by calling 'JarFile.getInputStream(ZipEntry ze)'. Well you can read data from the stream.

这篇关于读取 JAR 文件的内容(在运行时)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆