CPU架构
- 方法一:
使用System.getProperty方法可以获取系统相关属性,CPU架构类型可用System.getProperty("os.arch")
示例:
public class SystemProperty { public static void main(String args[]) { System.out.println("os_name:" + System.getProperty("os.name")); System.out.println("os_arch:" + System.getProperty("os.arch")); }
鲲鹏上执行结果:
[root@centos7 test]# Java SystemProperty os_name:Linux os_arch:aarch64
- 方法二:
调用ManagementFactory.getOperatingSystemMXBean()方法获取。
代码示例:
import Java.lang.management.ManagementFactory; import com.sun.management.OperatingSystemMXBean; public class SystemProperty { public static void main(String args[]) { OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementF actory.getOperatingSystemMXBean(); String osArch = osmxb.getArch(); System.out.println("osArch: " + osArch); }
鲲鹏上执行结果:
[root@centos7 test]# Java SystemProperty osArch: aarch64
父主题: Java