How to test for Windows 7 platform?

笑着哭i 提交于 2019-12-08 18:58:44

问题


I have a Java app which needs to run differently when on Windows 7.

How would you check which Windows version is present? Is it enough to check for OS version 6.1?


回答1:


I've solved the same problem checking also for os.name, in a null-safe way:

public boolean runningOnWindows7() {
    String osName = System.getProperty("os.name");
    String osVersion = System.getProperty("os.version");
    return "Windows 7".equals(osName) && "6.1".equals(osVersion);
}



回答2:


OS Version Numbers are rather distinct.

For example, XP is denoted with the number 5.1 and Windows 7 denoted by 6.1

The build numbers determine the updates, and service packs.

It should be rather reliable checking OS version number. but keep in mind that Java is allowed to run on Linux and Mac if Java is installed on the machine.




回答3:


System.getProperty("os.name") 
System.getProperty("os.version")

Windows 7 = version 6.1




回答4:


Fix to dfa's answer:

public boolean runningOnWindows7() {
    String osName = System.getProperty("os.name");
    String osVersion = System.getProperty("os.version");
    return "Windows 7".equals(osName) || "6.1".equals(osVersion);
}

|| instead of &&



来源:https://stackoverflow.com/questions/2272972/how-to-test-for-windows-7-platform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!