• System类

  代表当前Java程序的运行平台。

  • Runtime类

  代表Java程序的运行时环境,每个Java程序都有一个与之对应的Runtime实例,应用程序不能创建自己的Runtime实例,但可以通过Runtime.getRuntime()方法获取与之相关的Runtime对象。可以访问JVM的相关信息,如处理器数量/内存信息等。

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;

public class SystemTest {

    public static void main(String[] args) throws Exception, IOException {
        Map<String, String> env = System.getenv();
        for (String name : env.keySet()) {
            System.out.println(name + "--->" + env.get(name));
        }
        
        System.out.println(System.getenv("JAVA_HOME"));
        Properties props = System.getProperties();
        props.store(new FileOutputStream("props.txt"), "System Properties");
        
        System.out.println(System.getProperty("os.name"));
    }
}
posted on 2017-01-24 15:12  coder为  阅读(133)  评论(0编辑  收藏  举报