最近我在一個品牌的移動新機的64位Windows 7。但是,當我運行這段代碼,得到不正確的操作系統名稱不正確的操作系統名稱在Java中獲得
String osName = System.getProperty("os.name");
System.out.println("OS Name = " + osName);
輸出談到:
OS Name = Windows Vista
任何想法,我的代碼或系統有什麼問題?
在此先感謝。
最近我在一個品牌的移動新機的64位Windows 7。但是,當我運行這段代碼,得到不正確的操作系統名稱不正確的操作系統名稱在Java中獲得
String osName = System.getProperty("os.name");
System.out.println("OS Name = " + osName);
輸出談到:
OS Name = Windows Vista
任何想法,我的代碼或系統有什麼問題?
在此先感謝。
您可能正在使用舊版本的Java。因爲這是一個已知的bug(bug_id = 6819886),已在新版本中修復。 Kindly read this for further details。
的情況下,可能的解決方法對於這一點,你無法升級您的Java版本:
String osName = System.getProperty("os.name");
if (osName.equals("Windows XP") || osName.equals("Windows Vista"))
{
//do something and remember to put in all the names in the above if list. I just added two for example,it will have to include all like Windows NT,ME,95,etc.
}
else
{
//the block that will be accessible for Windows 7
}
使用JAVA-6,我試過它的工作正常,否則你的Windows使用Vista模式對待JVM。
最近出現了同樣的問題。正如bug 6819886評估說明所述,您可以檢查os.version屬性以區分Windows 7和Windows Vista在這種情況下。
版本的Windows 7是6.1和Windows Vista的是6
String osVersion = System.getProperty("os.version");
if("6.1".equals(osVersion)){
System.out.println("OS is Windows 7");
}
這樣你就不必升級到最新的Java只是爲了使這項工作。
也許Windows在「Vista模式」(兼容模式)下運行您的JVM? – Hassan
由於我們的項目依賴關係,我正在使用java.version = 1.5.0_16。 – Kishore