如何在 Java 中保存首选项用户设置?
例如,我有一个带有首选项按钮的窗口。 我想这样做,以便当用户按下首选项按钮并检查他/她的适当选项并按确定时,它会保存首选项,然后当用户在主窗口上按下运行时,它会相应地运行用户在首选项上更改的首选项窗户。
先感谢您。
For example, I have a window with a preference button.
I want to make it so that when user press the preference button and checks his/her appropriate options and press ok, it saves the preference, then when user presses run on the main window, it runs accordingly to preference the user changed on the preference window.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 java.util.prefs< /a> 包。一个简单的例子:
java2s.com 还有更多示例。
You can use java.util.prefs package. A simple example:
There are many more examples at java2s.com.
有一个专门用于此目的的 Java Preferences API目的。它允许您以简单的跨平台方式存储每个用户的首选项,而 API 本身负责存储数据的位置和方式。
There is a Java Preferences API specifically for this purpose. It lets you store per-user preferences in an easy cross-platform way, while the API itself takes care of where and how to store the data.
您可以使用
java.util.Properties
来保存您的首选项You may use
java.util.Properties
to save your preferences