如何在Java中制作类似于jar -uf的功能?
使用标准的Java API(即用户不需要JDK来运行它),如何在Java中制作类似于jar -uf的功能?我有一个想法,它将使用 Zip 库,解压缩 .jar 文件,更改内容,然后重新压缩它,但我是 Java 新手,所以我无法真正做到。能给个例子或者函数吗?
谢谢!
编辑:我想我在这里找到了答案:如何使用 JarOutputStream创建 JAR 文件? 我看看是否有效。
Using the standard Java API (i.e. the user doesn't need the JDK to run it), how do you make a function similar to jar -uf in Java? I have an idea that it will use the Zip library, unzip the .jar file, change the contents, and then rezip it, but I'm a newbie at Java, so I cannot really make it. Could you give an example or a function?
Thanks!
Edit: I think I found the answer here: How to use JarOutputStream to create a JAR file?
I'll see if it works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下JarInputStream,< a href="http://docs.oracle.com/javase/7/docs/api/java/util/jar/JarOutputStream.html" rel="nofollow">JarOutputStream, ZipInputStream 和 ZipOutputStream。它们是 JDK 的一部分,因此不需要外部库。请注意,与其他流不同,这些流需要您关心当前条目。您可以找到很多有关如何使用 java zip API 的示例。
Take a look at JarInputStream, JarOutputStream, ZipInputStream, and ZipOutputStream. They are a part of the JDK, so external libraries are not required. Pay attention that unlike other streams these require you to care about current entry. You can find a lot of examples of how to use the java zip API.