Runtime

Runtime

 

Runtime

package com.mao.one;

import java.io.IOException;

public class RuntimeDemo01 {

    public static void main(String[] args) throws IOException {
//        //1.获取runtime的对象
//        Runtime r1 = Runtime.getRuntime();
//        System.out.println(r1);

//        //2.exit 停止虚拟机
//        Runtime r1 = Runtime.getRuntime();
//        r1.exit(0);
//
//        System.out.println("看看我执行了吗");

        //3.获取CPU的线程数
//        System.out.println(Runtime.getRuntime().availableProcessors());
//
        //4.总内存,单位byte
//        System.out.println(Runtime.getRuntime().maxMemory() / 1024 / 1024 );
//        //5.已经获取内存的大小
//        System.out.println(Runtime.getRuntime().totalMemory()/ 1024 / 1024);
//        //6.剩余内存的大小
//        System.out.println(Runtime.getRuntime().freeMemory()/ 1024 / 1024 );
        //7.运行 cmd 命令
        //shutdown :关机
        //加上参数才能执行
        //-s :默认一分钟后关机
        //-s -t 指定时间 :指定关机时间
        //-a :取消关机操作
        //-r'  :关机并重启
        Runtime.getRuntime().exec("notepad");
    }
}

 

posted @ 2022-08-16 18:13  是貓阿啊  阅读(68)  评论(0)    收藏  举报