共计 465 个字符,预计需要花费 2 分钟才能阅读完成。
依据 System.getProperty(“os.name”) 值判断
public class OS {
public enum PlatformEnum {MAC, LINUX, WINDOWS;}
private static PlatformEnum platform;
public static PlatformEnum platform() {if(platform == null) {String os = System.getProperty("os.name");
String osName = System.getProperty("os.name");
System.out.println(osName);
if (osName.startsWith("Mac OS")) {platform = PlatformEnum.MAC;} else if (osName.startsWith("Windows")) {platform = PlatformEnum.WINDOWS;} else {platform = PlatformEnum.LINUX;}
}
return platform;
}
}
正文完