java程序控制系统中其他程序的方法

来源:互联网 发布:第三方支付有哪些 知乎 编辑:程序博客网 时间:2024/05/27 14:13

import java.io.IOException;import java.io.InputStream;public class Testwindow {/** * @param args * @throws IOException */public static void main(String[] args) throws IOException {// window下Runtime rt = Runtime.getRuntime();// Process process=rt.exec("cmd /c start dir");// 说明:&在cmd中作为关键字保留,还有空格等 你最好都转义一下 前面加^ 就行// Process process2=rt.exec("cmd /c start http://www.sina.com");// 在linux下//Process process2 = rt.exec("gedit");Process process2 = rt.exec("ls /");InputStream is=process2.getInputStream();int i=0;byte[] b=new byte[1024];while((i=is.read(b))!=-1){System.out.println(new String(b,0,i));}System.out.println(process2);}}




原创粉丝点击