import java.util.prefs. * ; import java.util. * ; public class PreferencesDemo ... { /** *//** * @param args */ public static void main(String[] args) throws Exception ...{ // TODO 自动生成方法存根 Preferences prefs = Preferences.userNodeForPackage(PreferencesDemo.class); prefs.put("Location","CN"); prefs.put("Footware","Hello Citte"); prefs.putInt("Companions",4); prefs.putBoolean("Are there witches?",true); int usageCount = prefs.getInt("UsageCount",0); usageCount++; prefs.putInt("UsageCount",usageCount); Iterator it = Arrays.asList(prefs.keys()).iterator(); while (it.hasNext()) ...{ String key = it.next().toString(); System.out.println(key + ":" + prefs.get(key,null)); } System.out.println("How many Companions dos Donothy hava ?" + prefs.getInt("Companions",0)); } }