Java简单模拟ping

xiaoxiao2021-02-28  6

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Ping { public static void pingCommand(String ping){ try { Process process=Runtime.getRuntime().exec(ping); try { process.waitFor();//等待子进程完成再往下执行 } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } BufferedReader br=new BufferedReader(new InputStreamReader( process.getInputStream())); String line=null; while((line=br.readLine())!=null){ System.out.println(line); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void main(String[] args) { Ping.pingCommand("ping 127.0.0.1"); } }
转载请注明原文地址: https://www.6miu.com/read-1150365.html

最新回复(0)