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

前端之家收集整理的这篇文章主要介绍了Java中的操作系统名称不正确前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
最近我移动了一台全新的64位 Windows 7机器.但是当我运行这个代码,得到不正确的操作系统名称
String osName = System.getProperty("os.name");
System.out.println("OS Name = " + osName);

输出来:

OS Name = Windows Vista

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

提前致谢.

解决方法

您可能会使用旧版本的Java.因为这是在较新版本中已经修复的已知错误(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
    }
原文链接:https://www.f2er.com/java/122573.html

猜你在找的Java相关文章