[英]Getting the Windows kernel version in Java?
我想在Windows中使用Java獲取內核版本。 Java中是否有任何類可以獲取信息?
我能夠使用System.getProperty("os.name");
找到操作系統名稱System.getProperty("os.name");
,但我想要內核版本。
使用ver命令,您可以獲得更精確的內核版本(如果需要)
您可以使用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();
}
結果(例子)
Microsoft Windows [Version 6.1.7601]
你試過了嗎 :
System.getProperty("os.version");
如果您想在Linux或Android上檢查相同內容,可以通過以下聲明進行檢查:
Runtime.getRuntime().exec("uname -r");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.