我想问下,如何使用java程序调出dos窗口来实现ping ip的功能?(注意,要弹出dos窗口显示ping信息)。谢谢。
我是个新手,请大家多多帮忙,谢谢。

解决方案 »

  1.   

    java.lang.Runtime.getRuntime().exec("cmd ping");
      

  2.   

    import java.io.IOException;
    import javax.swing.JOptionPane;public class RenewIP {
    public static void main(String[] args) {
    RenewIP rn = new RenewIP();
    Runtime runtime = Runtime.getRuntime();
    try {
    runtime.exec(rn.getClass().getResource("RenewIP.bat").getPath());
    } catch (IOException e) {
    e.printStackTrace();
    }
    JOptionPane.showMessageDialog(null, "IP刷新完毕.");
    }
    }
    RenewIP.bat里面写 @ipconfig /release
    @ipconfig /renew
    @pause   你改成ping命令就好..   .bat跟class 放同一目录
      

  3.   

    java.lang.Runtime.getRuntime().exec("cmd.exe /c start ping 127.0.0.1");
      

  4.   


    import java.io.IOException;public class Ping{ /**
     * @param args
     * String的split方法也是可以分割字符串的
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    try {
    Process process = java.lang.Runtime.getRuntime().exec("cmd /c start ping 127.0.0.1");
    process.waitFor();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();

    }
    }