Java中的操作系统名称不正确

Kis*_*ore 9 java windows-7

最近我搬到了一台全新的64位Windows 7机器上.但是当我运行这段代码时,得到了错误的操作系统名称

String osName = System.getProperty("os.name");
System.out.println("OS Name = " + osName);
Run Code Online (Sandbox Code Playgroud)

输出来了:

OS Name = Windows Vista
Run Code Online (Sandbox Code Playgroud)

任何想法,我的代码或系统有什么问题?

提前致谢.

Kaz*_*ara 12

您可能正在使用旧版本的Java.因为这是一个已知错误(bug_id = 6819886)已在新版本中修复. 请阅读此内容以获取更多详细信息.


如果您无法升级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
    }
Run Code Online (Sandbox Code Playgroud)