(1)本地和测试环境系统不一样,有时需要区别系统。
String systemVersions = System.getProperty("os.name");
if(systemVersions.indexOf("Windows") >= 0){
System.out.println("this is windows !");
}else if(systemVersions.indexOf("Linux") >= 0){
System.out.println("this is Linux !");
}else if(systemVersions.indexOf("Mac") >= 0){
System.out.println("this is Mac !");
}
注意获取到的系统名称首字母是大写的。
(2)进一步获取系统其它信息可以这样:
System.out.println(System.getProperty("os.name"));// 系统名称
System.out.println(System.getProperty("os.version"));// 版本
System.out.println(System.getProperty("os.arch"));// 处理器
结果如下:
Windows 7
6.1
amd64
Windows 10
10.0
amd64
Mac OS X
10.11.5
x86_64
(3)若想进一步深入了解更详细的系统信息,可参考
http://lopica.sourceforge.net/os.html