liangoogle

liangoogle
随笔 - 9, 文章 - 0, 评论 - 3, 引用 - 0
数据加载中……

URL对象的创建及使用 URL类中一些很基本的方法

URL类中一些很基本的方法如下:

·  public final Obect getContent() 这个方法取得传输协议。

·  public String getFile() 这个方法取得资源的文件名。

·  public String getHost() 这个方法取得机器的名称。

·  public int getPort() 这个方法取得端口号。

·  public String getProtocol() 这个方法取得传输协议。

·  public String toString() 这个方法把URL转化为字符串。

实例:URL对象的创建及使用

import java.net. *;
import java.io.*;
class Myurl  {
public static void main(String args[])   {
   try {
    URL url=new URL("http://www.tsinghua.edu.cn/chn/index.htm");
    System.out.println("the Protocol: "+url.getProtocol());
    System.out.println("the hostname: " +url.getHost());
    System.out.println("the port: "+url.getPort());
    System.out.println("the file:"+url.getFile());
System.out.println(url.toString());
}catch(MalformedURLException e) {
System.out.println(e);
     }
    }

}

posted on 2011-04-21 19:50 haojinlian 阅读(1057) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: