import java.net.InetAddress;
import java.net.UnknownHostException;
public class NetTest {
public static void main(String[] args)
{
InetAddress i = null;
try {
i = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
String address=i.getHostAddress();
String name=i.getHostName();
System.out.println(address+name);
try {
InetAddress p=InetAddress.getByName("www.baidu.com");
} catch (UnknownHostException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
String address1=i.getHostAddress();
String name2=i.getHostName();
System.out.println(address1+name2);
}
}
提示java.net.UnknownHostException: www.baidu.com |
|