Java Preferences API 使用自定义文件?
是否可以使用首选项 API 将应用程序的设置存储在自定义文件中?据我所知,在 Windows 中,首选项存储在注册表中,恕我直言,这不是一个好主意,我希望我的应用程序将首选项保存到 D:\app.preferences。是否可以?
Is it possible to use Preferences API to store my application's settings in a custom file? From what I have read, in Windows preferences are stored in registry which is not a good idea imho and I want my app to save prefs to let's say D:\app.preferences. Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首选项
API 的目的是使应用程序程序员不必了解操作系统如何选择保存用户首选项。如果您想将首选项保存在特定文件中,您当然可以这样做。只需使用 Properties 实例来读取/写入您想要的文件。the point of the
Preferences
API is to make it so that the application programmer doesn't have to know anything about how the OS chooses to save user preferences. if you want to save preferences in a specific file, you can certainly do that. just use a Properties instance to read/write to the file you desire.您可以实现自己的 Preferences,只需查看 Linux 实现 内部使用文件。您只是无法使用首选项中的静态方法来获取根源,但您必须自己将它们存储在某个地方。
You can implement your own Preferences, just look at the Linux implementation which internally uses a file. You just wont be able to use the static methods in Preferences to get at the roots but you have to store them somewhere yourself.
通过导出和导入首选项,您可以获得您想要的。它还将存储在 JAVA 选择的任何特定于操作系统的存储机制中
By exporting and importing the preferences you can have what you want. It will still also be stored in wherever/whatever OS-specific storage mechanism JAVA chooses