乐趣区

关于java:Java判断操作系统

依据 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;
    }

}
退出移动版