/Users/lyon/j4p/src/futils/PreferencesExample.java
|
1 package futils;
2
3 import java.util.prefs.Preferences;
4 import java.util.prefs.BackingStoreException;
5
6 /**
7 * Copyright DocJava, inc. User: lyon
8 * <p/>
9 * Date: Nov 7, 2004
10 * <p/>
11 * Time: 6:55:44 AM
12 */
13 public class PreferencesExample {
14 public static void main(String[] args) {
15 putData("\\this is a test\\:");
16 printData();
17 printKeys();
18
19 }
20
21 private static void printData() {
22 System.out.println(getData());
23 }
24 public static void printKeys(){
25 Preferences p = Preferences.userRoot();
26 try {
27 String sa[] = p.keys();
28 for (int i=0; i < sa.length; i++)
29 System.out.println(sa[i]);
30 } catch (BackingStoreException e) {
31 e.printStackTrace();
32 }
33 }
34 private static String getData() {
35 Preferences p = Preferences.userRoot();
36 return p.get("com.docjava.foo", null);
37 }
38
39 private static void putData(String s) {
40 Preferences p = Preferences.userRoot();
41 p.put("com.docjava.foo", s);
42 }
43 }
44