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)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 平遥县| 平江县| 手游| 东安县| 上林县| 锡林郭勒盟| 通州区| 桂东县| 洪泽县| 长丰县| 汉川市| 曲水县| 哈密市| 丰台区| 科技| 时尚| 饶阳县| 肃宁县| 孙吴县| 鄯善县| 璧山县| 昌邑市| 玛纳斯县| 砀山县| 旬阳县| 启东市| 班玛县| 茶陵县| 呼和浩特市| 托克逊县| 周口市| 辽阳市| 四川省| 藁城市| 高密市| 淮阳县| 若尔盖县| 德令哈市| 体育| 隆林| 巴楚县|