package com.zmd.common_class_libraries; import java.util.Map; /** * @ClassName SystemExample * @projectName: object1 * @author: Zhangmingda * @description: XXX * date: 2021/4/6. */ public class SystemExample { public static void main(String[] args) { Map<String, String> envMap = System.getenv(); for (String key : envMap.keySet()) { String value = envMap.get(key); System.out.println(key + "=" + value); } System.out.println("-------------------------"); System.out.println(System.getenv("JAVA_HOME")); } }
Runtime runtime = Runtime.getRuntime(); 不用new 直接引用静态方法即可
package com.zmd.common_class_libraries; import java.io.IOException; /** * @ClassName RuntimeExample * @projectName: object1 * @author: Zhangmingda * @description: XXX * date: 2021/4/6. */ public class RuntimeExample { public static void main(String[] args) throws IOException { //不用new关键字,直接用类的静态方法,获取当前运行时环境 Runtime runtime = Runtime.getRuntime(); //获取CPU核心数 System.out.println("处理器数量:" + runtime.availableProcessors()); //获取可用最大内存 System.out.println("最大可用内存:" + runtime.maxMemory()); //获取java虚拟机的总内存大小 System.out.println("JAVA虚拟机总内存totalMemeory:" + runtime.totalMemory()); //空闲内存 System.out.println("空闲内存:" + runtime.freeMemory()); //通过java启动系统exe文件例如QQ音乐 runtime.exec("\"C:\\Program Files (x86)\\Tencent\\QQMusic\\QQMusic.exe\""); } }
java 常用类库:操作系统System类,运行时环境Runtime
原文:https://www.cnblogs.com/zhangmingda/p/14623329.html