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 閱讀(1070) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 秦皇岛市| 萨嘎县| 眉山市| 美姑县| 丹阳市| 东明县| 博野县| 岗巴县| 象山县| 石阡县| 屏东市| 铜梁县| 漳浦县| 房产| 鞍山市| 江川县| 敦煌市| 宽城| 临夏县| 龙井市| 英山县| 莱西市| 辰溪县| 垦利县| 河间市| 马龙县| 长垣县| 九台市| 临泽县| 驻马店市| 扶余县| 屏边| 东安县| 卓尼县| 双辽市| 广德县| 肥城市| 略阳县| 任丘市| 新余市| 景德镇市|