欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

java实现ping

程序员文章站 2023-11-10 10:54:58
java实现ping...
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());
}
}
}
}
}

相关标签: Java Ping