简体   繁体   English

用Java获取Windows内核版本?

[英]Getting the Windows kernel version in Java?

I want to get the kernel version in Windows using Java. 我想在Windows中使用Java获取内核版本。 Is there any class in Java to get the info? Java中是否有任何类可以获取信息?

I am able to find the OS name using System.getProperty("os.name"); 我能够使用System.getProperty("os.name");找到操作系统名称System.getProperty("os.name"); , but I want the kernel version instead. ,但我想要内核版本。

With the ver command you can get a more precise kernel version (if needed) 使用ver命令,您可以获得更精确的内核版本(如果需要)

You can execute it using cmd and then parse it 您可以使用cmd执行它,然后解析它


  final String dosCommand = "cmd /c ver";
      final String location = "C:\\WINDOWS\\SYSTEM32";
      try {
         final Process process = Runtime.getRuntime().exec(
            dosCommand + " " + location);
         final InputStream in = process.getInputStream();
         int ch;
         while((ch = in.read()) != -1) {
            System.out.print((char)ch);
         }
      } catch (IOException e) {
         e.printStackTrace();
      }

Result (example) 结果(例子)

Microsoft Windows [Version 6.1.7601]

Did you try : 你试过了吗 :

System.getProperty("os.version");

If you want to check the same on Linux or Android you can do so by this statement: 如果您想在Linux或Android上检查相同内容,可以通过以下声明进行检查:

Runtime.getRuntime().exec("uname -r");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM