java实现ping
发布时间:2017-01-04 来源:查字典编辑
摘要:importjava.io.*;importjava.lang.*;publicclassPing{publicPing(){}public...
import java.io.*;
import java.lang.*;
public class Ping{
public Ping() {
}
public static void main(String args[])
{
String[] addrs= {"www.sina.com"};
if (addrs.length < 1)
{
System.out.println("syntax Error!");
}
else
{
for(int i=0;i<addrs.length;i++){
String line = null;
try
{
Process pro = Runtime.getRuntime().exec("ping " + addrs[i]);
BufferedReader buf = new BufferedReader(new InputStreamReader(pro.getInputStream()));
while((line = buf.readLine()) != null)
System.out.println(line);
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
}
}
}