URL 类 示例

来源:互联网 发布:淘宝教程新手入门视频 编辑:程序博客网 时间:2024/06/03 18:28

//Demonstrate URL.
import java.net.*;
class URLDemo{
 public static void main(String[] args) throws MalformedURLException{
  URL hp = new URL("http://www.sina.com/download");

  System.out.println("Protocol: " + hp.getProtocol());
  System.out.println("Port: " + hp.getPort());
  System.out.println("Host: " + hp.getHost());
  System.out.println("File: " + hp.getFile());
  System.out.println("Ext: " + hp.toExternalForm());
 }