怎么实现ping命令 并能获取他的返回值

2025-02-27 05:50:33
推荐回答(2个)
回答1:

public static void main(String[] args) throws IOException, InterruptedException {

     // 执行ping命令

     String cmdPing = "ping www.baidu.com";

     Runtime run = Runtime.getRuntime();

     Process process = run.exec(cmdPing);

     process.waitFor();

    BufferedReader reader = new BufferedReader(new     InputStreamReader(process.getInputStream(), Charset.forName("GBK")));

     String line = null;

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

     System.out.println(line);

     }

}

回答2:

点触摸板就可以实现的功能干嘛要用原始的命令行?