import java.util.prefs.Preferences; public class Pref { public static void main(String args[]) { if (args.length < 2) { System.out.println("Usage: java Pref [add|get] pref [value]"); System.exit(0); } Preferences prefs = null; if (args[0].equals("add")) { // Add Pref prefs = Preferences.userRoot().node(KEY); prefs.put(args[1], args[2]); System.out.println("Done!"); } else if (args[0].equals("get")) { // Get Pref prefs = Preferences.userRoot().node(KEY); String value = prefs.get(args[1], "default"); System.out.println(value); } System.out.println("Prefs = " + prefs.toString()); } private static String KEY = "/foo/bar/key"; }