在java中调用windows命令

来源:互联网 发布:mysql登录失败限制 编辑:程序博客网 时间:2024/06/05 13:24

import java.io.*;

 

/**

 * java中调用windows命令

 *

 * @author Norez

 *

 */

public class RuntimeExec {

 

       public static void main(String[] args) throws java.io.IOException {

              Runtime run = Runtime.getRuntime();

 

              Process process = run.exec("ping 192.168.1.1");

 

              InputStream is = process.getInputStream();

              InputStreamReader isr = new InputStreamReader(is);

              BufferedReader br = new BufferedReader(isr);

              String line = "";

              while ((line = br.readLine()) != null) {

                     System.out.println(line);

              }

              br.close();

              isr.close();

              is.close();

 

       }

 

}