Incorrect OS name getting in Java

You might be using an older version of Java. As this was a known bug(bug_id=6819886) that has been fixed in the newer versions. Kindly read this for further details.


A possible workaround for this in case you are not able to upgrade your java version:

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
    }

There is a bug reported regarding this:

http://bugs.sun.com/view_bug.do?bug_id=6819886

Not sure if it is fixed in newer versions of Java as I do not have Java 7.

Tags:

Java

Windows 7