Java's “os.name” for Windows 10?

后端 未结 5 1339
离开以前
离开以前 2020-12-01 13:49

In Java, we can see the property value of os.name to know the name of the underlying operating system: System.getProperty(\"os.name\").

For

5条回答
  •  鱼传尺愫
    2020-12-01 14:14

    I faced the same issue, used the following workaround: The cmd command "systeminfo" returns "OS Name:" which is the right name for the OS, wrote the following function for this:

    private boolean os2k10Check()
    {
    try{
    
        Process p = Runtime.getRuntime().exec("systeminfo");        /*Execute cmd command "systeminfo"*/
        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while (true) 
        {
            line = r.readLine();
            if (line == null) { break; }
            if(line.contains("OS Name:"))               /*If output contains OS Name and 2010*/
            {
            if(line.contains("2010"))
                    return true;
            else
                    return false;       
            }
        }
    }
    catch(Exception e)
        {System.out.println("Platform Type: os2010check: exception"+e);}
    
    return false;
    }
    

提交回复
热议问题