木木甫 2017-02-25 06:43 采纳率: 35.7%
浏览 961
已采纳

java创建注册表失败,????

 /**
 * Created by demo on 2017/2/25.
 */
import com.ice.jni.registry.NoSuchKeyException;
import com.ice.jni.registry.RegStringValue;
import com.ice.jni.registry.Registry;
import com.ice.jni.registry.RegistryException;
import com.ice.jni.registry.RegistryKey;
/**
 * @author solo L
 *
 */
class JNIRegistryTest {

    public  void openRegistry(){
        //打开注册表项并读出相应的值
        try {
            RegistryKey software = Registry.HKEY_LOCAL_MACHINE.
                    openSubKey("SOFTWARE");
            RegistryKey subKey = software.openSubKey("ymbizhi");
            String subKey1Value = subKey.getStringValue("Channel");
            String subKey2Value = subKey.getStringValue("InstallTime");
            System.out.println(subKey1Value);
            System.out.println(subKey2Value);
            subKey.closeKey();
        } catch (NoSuchKeyException e) {
            e.printStackTrace();
        } catch (RegistryException e) {
            e.printStackTrace();
        }
    }
    public void createRegist(){
        //创建注册表项并设置相应的值
        try {
            RegistryKey software = Registry.HKEY_LOCAL_MACHINE
                    .openSubKey("SOFTWARE");
            RegistryKey subKey = software.createSubKey("SubKeyName", "");
            subKey.setValue(new RegStringValue(subKey, "subKey1",
                    "subKey1Value"));
            subKey.setValue(new RegStringValue(subKey, "subKey2",
                    "subKey2Value"));
            subKey.closeKey();
        } catch (NoSuchKeyException e) {
            e.printStackTrace();
        } catch (RegistryException e) {
            e.printStackTrace();
        }
    }

}

单元测试:

 import org.junit.Test;

import static org.junit.Assert.*;

/**
 * Created by demo on 2017/2/25.
 */
public class JNIRegistryTestTest {

    private JNIRegistryTest regist = new JNIRegistryTest();

    @Test
    public void openRegistry() throws Exception {
        regist.openRegistry();
    }

    @Test
    public void createRegist() throws Exception {
        regist.createRegist();
    }

}

图片说明

  • 写回答

3条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥20 苹果app名字侵权商标,我投诉了,但是苹果一直没回怎么办
      • ¥15 Android studio运行不成功总是报错
      • ¥15 pycharm 加载软件包列表时出错connect timed out
      • ¥15 和您碰到了同一个问题
      • ¥15 如何在微信支付V3PHP版请求中添加header?
      • ¥15 在数字信号处理中用MATLAB显示波形。
      • ¥15 keil MDK软件进行仿真调试的局限
      • ¥15 关于gateway产生临时文件夹的问题
      • ¥15 Java Broken Pipe以及OOM
      • ¥20 请问有没有RTL8211FS的参考原理图