系统相关
首页 > 系统相关> > JAVA-获取内存和系统类型

JAVA-获取内存和系统类型

作者:互联网

  protected long getMemory() {
        OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
        return osmxb.getTotalPhysicalMemorySize();
    }

  

protected String getOsType() {
        String osName = System.getProperty("os.name");
        if (osName.startsWith("Linux"))
            return "Linux";
        if (osName.startsWith("Windows"))
            return "Windows";
        if ((osName.contains("SunOS")) || (osName.contains("Solaris")))
            return "Solaris";
        if (osName.contains("Mac"))
            return "Mac";
        if (osName.contains("FreeBSD")) {
            return "FreeBSD";
        }
        return "Other";
    }

  



标签:startsWith,return,String,contains,osName,获取,Mac,内存,JAVA
来源: https://www.cnblogs.com/becoding/p/14090457.html