用java窗口界面实现调用系统的ping 命令 界面中只要输入ip地址和要ping的次数 且下面要有返回信息.大虾请帮忙:感谢!

解决方案 »

  1.   

      public static void main(String[] args) throws IOException {
        Runtime run = Runtime.getRuntime();
        Process pro = run.exec("ping 127.0.0.1 -t ");
        BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream()));
        String str = "";
        while ((str = br.readLine()) != null) {
          System.out.println(str); // 这里你增加一个计数器,判断行数
        }
        br.close();
        pro.destroy();
      }
      

  2.   

      public static void main(String[] args) throws IOException {
        Runtime run = Runtime.getRuntime();
        Process pro = run.exec("ping 127.0.0.1 -t ");
        BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream()));
        String str = "";
        while ((str = br.readLine()) != null) {
          System.out.println(str); // 这里你增加一个计数器,判断行数
        }
        br.close();
        pro.destroy();
      }
      

  3.   

    使用Java的Runtime 就可以了,代码如下:
    /*
     * Created on Jan 3, 2008
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    package org.mytech.test;import java.io.*;/**
     * @author 806883
     * 
     * TODO To change the template for this generated type comment go to Window -
     * Preferences - Java - Code Style - Code Templates
     */public class RunPing { public static void main(String[] argv) {
    try {
    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec("ping www.163.com");
    BufferedReader reader = new BufferedReader(new InputStreamReader(
    process.getInputStream()));
    String line;
    while ((line = reader.readLine()) != null) {
    System.out.println(line);
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }