加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java中的配置文件

发布时间:2020-12-15 08:44:56 所属栏目:Java 来源:网络整理
导读:我创建了一个Swing Application-GUI,其中包含TextFields,Labels,CheckBoxes和ComboBoxes等字段.当用户输入一些信息时,我希望将文本字段,组合框和复选框的详细信息保存到文件中,下次用户打开此窗口时,我想要保存在文件中的详细信息,即那些用户输入的上一次加
我创建了一个Swing Application-GUI,其中包含TextFields,Labels,CheckBoxes和ComboBoxes等字段.当用户输入一些信息时,我希望将文本字段,组合框和复选框的详细信息保存到文件中,下次用户打开此窗口时,我想要保存在文件中的详细信息,即那些用户输入的上一次加载到GUI中.有人可以帮我这样做吗?我希望你理解这个问题,如果没有,我会以更详细的方式解释.

非常感谢你提前.

解决方法

以下是使用 java.util.prefs软件包的简单示例:

// Retrieve the user preference node for the package com.mycompany
Preferences prefs = Preferences.userNodeForPackage(com.mycompany.MyClass.class);

// Preference key name
final String PREF_NAME = "name_of_preference";

// Set the value of the preference
String newValue = "a string";
prefs.put(PREF_NAME,newValue);

// Get the value of the preference;
// default value is returned if the preference does not exist
String defaultValue = "default string";
String propertyValue = prefs.get(PREF_NAME,defaultValue); // "a string"

保存首选项的方式取决于操作系统.在Windows上,它将使用注册表.

使用实例:http://www.exampledepot.com/egs/java.util.prefs/pkg.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读