-
目录
-
网络基础知识
Ipv4地址(32位,4个字节)
Ipv6地址(128位,16个字节)
主机名(hostname)如:www.tsinghua.edu.cn
端口号(postnumber)如:80,21,23,1-1024为保留端口号
服务类型(service)如:http,telnet,ftp,smtp
-
通过URL读取www信息
Ipv4地址(32位,4个字节)
Ipv6地址(128位,16个字节)
主机名(hostname)如:www.tsinghua.edu.cn
端口号(postnumber)如:80,21,23,1-1024为保留端口号
服务类型(service)如:http,telnet,ftp,smtp
public class URLReader{
public static void main(String[] args)throws Exception{
URL cs=new URL("http://www.sina.com/");
BufferedReader in=new BufferedReader(new InputStreamReader(cs.openStream()));
String inputLine;
while((inputLine=in.readLine())!=null)
System.out.println(inputLine);
in.close();
}
}
-
构造URL对象
public URL(String spec)
URL urlBase=new URL("http://www.gamelan.com/");
public URL(URL context,String spec)
URL gamelanGames=new URL(gamelan,"Gamelan.game.html");
public URL(String protocol,String host,String file);
URL gamelan=new URL("http","www.gamelan.com","/pages/Gamelan.net.html");
public URL(String protocol,String host,int port,String file);
URL gamelan=new URL("http","www.gamelan.com",80,"pages/Gamelan.network.html");
-
获取URL对象属性
public String getProtocol()
public String getHost()
public String getport()
public String getFile()
public String getRef()