I am using system prefrences for testing my code i observed some peculiar things on java 1.5
private void loadEmptyPreferences() throws IOException,
InvalidPreferencesFormatException, BackingStoreException {
ClassLoader contextClassLoader = Thread.currentThread()
.getContextClassLoader();
InputStream stream = contextClassLoader
.getResourceAsStream("example.xml");
if (stream == null) {
fail("Could not load preferences file");
}
Preferences pref = Preferences.systemRoot().node("test");
pref.removeNode();
Preferences.importPreferences(stream);
}
I get
java.lang.SecurityException: Could not lock System prefs.Lock file access denied. at java.util.prefs.FileSystemPreferences.checkLockFile0ErrorCode(FileSystemPreferences.java:919) at java.util.prefs.FileSystemPreferences.lockFile(FileSystemPreferences.java:908) at java.util.prefs.FileSystemPreferences.removeNode(FileSystemPreferences.java:656)
The reason is that the preferences-systems tries to write a lock file at a location where "normal" users have no write permissions on Linux (/opt/j2se/linux/ix86/j2se_1.5.0_22/jre/.systemPrefs/.system.lock)
How to solve this?Should we use properties?