[code=java] public static void main(String[] args)throws Exception{
InetAddress LocAdd = null;
InetAddress remAdd = null;
LocAdd = InetAddress.getLocalHost();
remAdd = InetAddress.getByName("http://bbs.itheima.com/");
System.out.println("本机地址:" + LocAdd);
System.out.println("外网地址:" + remAdd);
System.out.println("本机是否可达" + LocAdd.isReachable(5000));
URL url = new URL("http","http://bbs.itheima.com/",80,"/forum-26-1.html");
InputStream input = url.openStream(); //打开输入流
Scanner scan = new Scanner(input); //实例化
scan.useDelimiter("\n"); //设置分隔符号
while(scan.hasNext()){
System.out.println(scan.next());
}
}[/code]运行后 第5、11行报错
Exception in thread "main" java.net.UnknownHostException: http://bbs.itheima.com/
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1200)
at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
at java.net.InetAddress.getAllByName(InetAddress.java:1083)
at java.net.InetAddress.getAllByName(InetAddress.java:1019)
at java.net.InetAddress.getByName(InetAddress.java:969)
at edu.csdn.net.heima.exam.ninth.TcpExamtest.main(TcpExamtest.java:19) |
|