首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

process两种用法(1)

2012-11-20 
process两种用法(一)package interview.processimport java.io.BufferedReaderimport java.io.IOExcepti

process两种用法(一)

package interview.process;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;public class ProcessUsual{public static void main(String[] args){call("javac");call("cmd.exe /C dir");}public static void call(String cmd){Runtime rt = Runtime.getRuntime();Process pro = null;try{pro = rt.exec(cmd);// =======在waitfor之前必须调用这两个方法======//new StreamTool(pro.getInputStream()).start();new StreamTool(pro.getErrorStream()).start();// ===================================//pro.waitFor();}catch (InterruptedException e){e.printStackTrace();}catch (IOException e){e.printStackTrace();}System.out.println(pro.exitValue());}private static class StreamTool extends Thread{BufferedReader br = null;public StreamTool(InputStream is){br = new BufferedReader(new InputStreamReader(is));}public void run(){String line = null;try{while ((line = br.readLine()) != null){System.out.println(line);}}catch (IOException e){e.printStackTrace();}}}}

?

热点排行