Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect OS name getting in Java

Tags:

java

windows-7

Recently I moved on a brand new machine 64-bit Windows 7. But when I run this code, getting the incorrect OS name

String osName = System.getProperty("os.name");
System.out.println("OS Name = " + osName);

The output comes:

OS Name = Windows Vista

Any idea, what is wrong in my code or system?

Thanks in Advance.

like image 283
Kishore_2021 Avatar asked May 30 '12 05:05

Kishore_2021


1 Answers

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
    }
like image 159
Kazekage Gaara Avatar answered Oct 29 '22 21:10

Kazekage Gaara