How to write to an XML file inside a jar file?

心不动则不痛 提交于 2019-12-24 01:26:10

问题


Hi Java programmers. I badly need your help.

I have a JavaFX/Java ME application. I'm trying to modify an XML file inside my project's folder (soon to be packaged jar file).

The path of the file I want to write: /parseExample/service1.xml

Sadly, my application is a JavaFx/JavaME so it doesn't contain the library java.util.jar. So I can't use the jar classes.

Are there other ways to do that?


回答1:


Even in J2SE you should consider a Jar file as read only. In J2SE the only way to do it is either using external tools or recreating a new Jar file and overwriting the old one with the new.

My recommendation would be to find a storage location as listed below and use your XML file as a default, if you need to change the just put the new one in the storage location.

Your data storage options are the following:

As per http://developer.android.com/guide/topics/data/data-storage.html These are the possible storage locations you have available:
Shared Preferences - Store private primitive data in key-value pairs.
Internal Storage - Store private data on the device memory.
External Storage - Store public data on the shared external storage.
SQLite Databases - Store structured data in a private database.
Network Connection - Store data on the web with your own network server.



来源:https://stackoverflow.com/questions/3058435/how-to-write-to-an-xml-file-inside-a-jar-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!