Java判断操作系统:

private static String getOfficeHome() {
public static void main(String[] args) {
String osName = System.getProperty("os.name");//获取指定键(即os.name)的系统属性,如:Windows 7。
String OSname=null;
if (Pattern.matches("Linux.*", osName)) {
OSname="Linux";
} else if (Pattern.matches("Windows.*", osName)) {
OSname="Windows";
} else if (Pattern.matches("Mac.*", osName)) {
OSname="Mac";
}
System.out.println("This OS is "+OSname);
System.out.println("osName:"+osName);
}
}

输出结果:

Java判断操作系统:_第1张图片

你可能感兴趣的:(Java判断操作系统:)