I'm using the java.util.prefs package to store some information entered by users. My understanding, based on documentation and this question is that the actual (user node) preferences are stored in ~/Library/Preferences/
, in a file named after the package. So far, this all checks out: Whenever I store some data in the node, a file in this directory is created and using the command line tool plutil
, I can inspect it and find the stored data.
However: When I delete the file, and restart my program, the data is still there. I couldn't find anything about that in the documentation or source code. Any help appreciated.
The following code demonstrates the behaviour, see command line session below:
package de.unistuttgart.ims.PreferencesTest;
import java.io.IOException;
import java.util.prefs.Preferences;
public class Main {
Preferences preferences = Preferences.userNodeForPackage(Main.class);
static Main app;
static String KEY = "KEY";
static String DEFAULTVALUE = "DEFAULTVALUE";
public static void main(String[] args) throws IOException {
app = new Main();
app.doStuff();
}
public void doStuff() throws IOException {
System.err.println("Retrieving value:");
System.err.println(preferences.get(KEY, DEFAULTVALUE));
System.err.println("Setting value:");
char ch = (char) System.in.read();
preferences.put(KEY, String.valueOf(ch));
}
}
Command line session:
$ java de.unistuttgart.ims.PreferencesTest.Main
Retrieving value:
DEFAULTVALUE
Setting value:
5
$ rm ~/Library/Preferences/de.unistuttgart.ims.plist
$ java de.unistuttgart.ims.PreferencesTest.Main
Retrieving value:
5
Setting value:
4
How can this be? Or: Where else are preferences stored?