I've been working with the java.util.prefs.Preferences functionality (in Java 8, on a Windows machine). And it works, where I can write new keys to the Windows Registry. So, I use Preferences.systemRoot() to get the Preferences object for the system, and then use the node() method to get a Preferences object that maps to a node in the Windows Registry. And it's creating things fine.
The Key I'm using for the Node is a String in all capital letters ("RBI"). When I look at the node in the Windows Registry, it comes up as "/R/B/I", with forward slashes in the name.
I thought this was odd, so I've dug around a bit And it looks like this is intentional. I found the class that provides the implementation of Preferences on a Windows environment (java.util.prefs.WindowsPreferences) and the method is uses for building the values sent to the windows registry is a static method toWindowsName. In the JavaDoc for that....
/**
* Converts value's or node's name to its Windows representation
* as a byte-encoded string.
* Two encodings, simple and altBase64 are used.
* <p>
* <i>Simple</i> encoding is used, if java string does not contain
* any characters less, than 0x0020, or greater, than 0x007f.
* Simple encoding adds "/" character to capital letters, i.e.
* "A" is encoded as "/A". Character '' is encoded as '//',
* '/' is encoded as ''.
* The constructed string is converted to byte array by truncating the
* highest byte and adding the terminating <tt>null</tt> character.
* <p>
* <i>altBase64</i> encoding is used, if java string does contain at least
* one character less, than 0x0020, or greater, than 0x007f.
* This encoding is marked by setting first two bytes of the
* Windows string to '/!'. The java name is then encoded using
* byteArrayToAltBase64() method from
* Base64 class.
*/
So, the Simple encoding will, for capital letters, add a forward slash.
Does anyone know why this is required? I had thought that the Registry could handle case-sensitive values, but this seems to indicate that it can't?
I can work around this, I'm just curious why this was done.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…