import java.net.URL;
public class Test {
public static void main(String[] args)
throws Exception {
URL url = new URL("http://www.study-area.org/tips/linux_entry.htm");
System.out.println("URL 是 " + url.toString());
System.out.println("协议是 " + url.getProtocol());
System.out.println("文件名是 " + url.getFile());
System.out.println("主机是 " + url.getHost());
System.out.println("路径是 " + url.getPath());
System.out.println("端口号是 " + url.getPort());
System.out.println("默认端口号是 "
+ url.getDefaultPort());
}
}
运行结果为:
URL 是 http://www.study-area.org/tips/linux_entry.htm
协议是 http
文件名是 /tips/linux_entry.htm
主机是 www.study-area.org
路径是 /tips/linux_entry.htm
端口号是 -1
默认端口号是 80
end