用Java打开和编辑.jar文件? [英] Open and edit file in .jar with Java?

查看:392
本文介绍了用Java打开和编辑.jar文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您打算如何开启.jar内的.xml档案并进行编辑?

How would you go about opening an .xml file that is within a .jar and edit it?

我知道您可以...

InputStream myStream = this.getClass().getResourceAsStream("xmlData.xml");

但是如何打开xmlData.xml,编辑文件并将其保存在.jar ?我会发现这对于了解而不想编辑.jar ... 之外的文件很有用,并且应用程序需要一直运行。

But how would you open the xmlData.xml, edit the file, and save it in the .jar? I would find this useful to know and don't want to edit a file outside of the .jar... and the application needs to stay running the entire time!

谢谢!

推荐答案

Jar文件只是带有不同文件后缀的.zip文件,内容。因此,请使用 java.util.zip 下的类来读取和/或写入内容。

Jar files are just .zip files with different file suffix, and naming convention for contents. So use classes from under java.util.zip to read and/or write contents.

修改内容不是保证(甚至可能)影响运行系统,因为类加载器可能会缓存内容,因为它认为合适。

Modifying contents is not guaranteed (or even likely) to effect running system, as class loader may cache contents as it sees fit.

因此,可能更好地了解你实际上试图用这个实现。修改jar的内容在飞行中听起来像复杂和容易出错的方法...

So it might be good to know more about what you are actually trying to achieve with this. Modifying contents of a jar on-the-fly sounds like complicated and error-prone approach...

这篇关于用Java打开和编辑.jar文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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