package io;
import java.util.prefs.*;
import static net.mindview.util.Print.*;
public class PreferencesDemo {
public static void main(String[] args) throws Exception {
Preferences prefs = Preferences
.userNodeForPackage(PreferencesDemo.class);
prefs.put("Location", "Oz");
prefs.put("Footwear", "Ruby Slippers");
prefs.putInt("Companions", 4);
prefs.putBoolean("Are there witches?", true);
int usageCount = prefs.getInt("UsageCount", 50);
//getInt的第二个值为默认值,在取不到值的情况下返回这个值
int test = prefs.getInt("test", 50);
test++;
prefs.putInt("test", test);
usageCount++;
prefs.putInt("UsageCount", usageCount);
for(String key : prefs.keys())
print(key + ": "+ prefs.get(key, null));
// You must always provide a default value:
print("How many companions does Dorothy have? " +
prefs.getInt("Companions", 0));
}
}
我的是win7系统信息存储到了注册表的路径为:
HKEY_USERS\S-1-5-21-114763097-1062112306-2744478244-500\Software\JavaSoft\Prefs\io