Read/write to Windows registry using Java

前端 未结 24 1636
日久生厌
日久生厌 2020-11-21 05:45

How is it possible to read/write to the Windows registry using Java?

24条回答
  •  眼角桃花
    2020-11-21 06:10

    My previous edit to @David's answer was rejected. Here is some useful information about it.

    This "magic" works because Sun implements the Preferences class for Windows as part of JDK, but it is package private. Parts of the implementation use JNI.

    • Package private class from JDK java.util.prefs.WindowsPreferences: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/util/prefs/WindowsPreferences.java
    • JNI: http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/9b8c96f96a0f/src/windows/native/java/util/WindowsPreferences.c

    The implementation is selected at runtime using a factory method here: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/util/prefs/Preferences.java#Preferences.0factory

    The real question: Why doesn't OpenJDK expose this API to public?

提交回复
热议问题