在java中调用windows命令

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();

 

       }

 

}

你可能感兴趣的:(在java中调用windows命令)