java - java中的配置文件

标签 java file swing configuration configuration-files

我创建了一个 Swing 应用程序 - GUI,其中包含文本字段、标签、复选框和组合框等字段。当用户输入一些信息时,我希望将文本字段、组合框和复选框的详细信息保存到一个文件中,下次用户打开此窗口时,我想要保存在文件中的详细信息,即那些用户上次输入的内容将被加载到 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

关于java - java中的配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8037339/

相关文章:

java - 在 Java 中实现缓存以实现读取性能且完全不驱逐

.net - Process.Start 一个没有扩展名的文件

linux - 处理包含数字和字符串的文本文件 shell 脚本

java - JLists - 列表中的元素数

java - String.trim() 比 String.replace() 更快吗?

java - 从 JPanel 实例化 JDialog

java - 在 @PersistenceContext 中设置 unitName 的 Spring Hibernate 配置

java - 文件上传代码出错

java - Jtable 中单元格的行为(右键单击单元格内部)

java - JDesktopPane 边界 - JInternalFrame 未填满整个桌面