java如何开启一个dos窗口?

 
Java代码 复制代码
  1. try {   
  2.             Process process = Runtime.getRuntime().exec("cmd.exe");   
  3.             OutputStream outputStream = process.getOutputStream();   
  4.             final InputStream inputStream = process.getInputStream();   
  5.             new Thread(new Runnable(){   
  6.                 byte[] cache = new byte[1024];   
  7.                 public void run() {   
  8.                      System.out.println("listener started");   
  9.                     try {   
  10.                         while(inputStream.read(cache)!=-1){   
  11.                             System.out.println(new String(cache));   
  12.                     }   
  13.                     } catch (IOException e) {   
  14.                         //e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.   
  15.                     }   
  16.                 }   
  17.             }).start();   
  18.              outputStream.write(new byte[]{'d','i','r','/n'});   
  19.             //inputStream.   
  20.             int i = process.waitFor();   
  21.             System.out.println("i=" + i);   
  22.         } catch (Exception e) {   
  23.             e.printStackTrace();   
  24.         }  


明白了没?
ggmmaallee (初级程序员) 2008-06-02
Java代码 复制代码
  1. try {   
  2.           Process process = Runtime.getRuntime().exec("cmd.exe");   
  3.           final BufferedWriter outputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));   
  4.           final BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));   
  5.           new Thread(new Runnable() {   
  6.              String line;   
  7.   
  8.               public void run() {   
  9.                   System.out.println("listener started");   
  10.                   try {   
  11.                       while ((line=inputStream.readLine()) != null) {   
  12.                           System.out.println(line);   
  13.                       }   
  14.                   } catch (IOException e) {   
  15.                       //e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.   
  16.                   }   
  17.               }   
  18.           }).start();   
  19.           new Thread(new Runnable() {   
  20.               final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));   
  21.   
  22.               public void run() {   
  23.                   System.out.println("writer started");   
  24.                   String line;   
  25.                   try {   
  26.                       while ((line = br.readLine()) != null) {   
  27.                           outputStream.write(line + "/r/n");   
  28.                           outputStream.flush();   
  29.                       }   
  30.                   } catch (IOException e) {   
  31.                       //e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.   
  32.                   }   
  33.               }   
  34.           }).start();   
  35.           int i = process.waitFor();   
  36.           System.out.println("i=" + i);   
  37.       } catch (Exception e) {   
  38.           e.printStackTrace();   
  39.       }   
  40.   }  
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值