[英]Writing to a properties file in a JAR
I'm create an application that is going to be run on Windows, Mac OX and Linux. 我正在创建一个将在Windows,Mac OX和Linux上运行的应用程序。 I have a properties file storing user settings which need to be read and changed on the fly.
我有一个属性文件,其中存储需要实时读取和更改的用户设置。
A JAR file is compressed and is not meant to be changed on the fly which means I should write to an external file. JAR文件已压缩,并不意味着可以随时更改,这意味着我应该写入外部文件。
I'm using : 我正在使用 :
new FileInputStream("database")
new FileOutputStream("database")
How do I create a URL which is going to be consistent throughout all three operating systems. 如何创建将在所有三个操作系统中保持一致的URL。 The JAR is run as an application on the desktop and I would like the file to be stored somewhere discrete.
JAR在桌面上作为应用程序运行,我希望将文件存储在离散的位置。
I've tried reading from a local file in the same package as this class : 我试图从与此类相同的包中的本地文件中读取:
this.getClass().getResourceAsStream("database")
This works however I can't seem to create an output stream to write to the same file but this would be breaking the rule of changing a JAR file on the fly. 这行得通,但是我似乎无法创建输出流来写入同一文件,但这将违反即时更改JAR文件的规则。
There are plenty of good reasons for which you should not do this, off the top of my head: 有很多充分的理由使您不应该这样做,这是我的首要考虑:
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.