java Runtime类

java

public class Test {

public static void main(String[] args) throws UnsupportedEncodingException

{

Runtime r = Runtime.getRuntime();//获取Runtime实例

p(r.freeMemory());//剩余内存

p(r.totalMemory()/1024/1024);//总内存

p(r.maxMemory()/1024/1024);//最大可用内存

p(r.availableProcessors());//核心数

List list = new ArrayList();

for(int i=0;i<100000;i++)

{

list.add("aaaaaaaaaaaaaaaaaaaabbbbbbbbbbb");

}

p(r.freeMemory());//剩余内存

r.gc();//垃圾回收, 测试用 实际应用中不要显式调用!!

p(r.freeMemory());//剩余内存

String s = "";

try {

//执行命令不支持cd切换目录,可以把目录作为参数传进去

Process proc = r.exec("cmd.exe /c dir", null, new File("c:"));

//执行有回显的命令

proc = r.exec("cmd.exe /c dir");

//打开可执行文件

r.exec("D:\\Program Files\\cradio_chs\\CRadio.exe");

//执行脚本

proc = r.exec("cmd.exe /c C:\\Users\\Administrator\\Desktop\\哨兵启动.cmd");

//获取回显

BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream(),"gbk"));

while((s=br.readLine())!=null)

{

p(s);

}

//打开可执行文件

r.exec("C:\\Program Files\\Microsoft Office\\Office16\\WINWORD.EXE C:\\Users\\Administrator\\Desktop\\违章push规则变更.doc");

r.exec("C:\\Program Files\\Microsoft Office\\Office16\\WINWORD.EXE C:\\Users\\Administrator\\Desktop\\违章\" \"push规则.docx");//空格用 \" \"代替

r.exec("notepad.exe");

proc.waitFor();

} catch (Exception e) {

e.printStackTrace();

}

}

public static void p(Object o)

{

System.out.println(o);

}

}


以上是 java Runtime类 的全部内容, 来源链接: utcz.com/z/389588.html

回到顶部