簡單+勤奮

          保持輕松和清醒,你就無往而不勝

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            1 Posts :: 1 Stories :: 0 Comments :: 0 Trackbacks

          根據指定URL下載一個網頁的內容

          //import java.net.*
          def url= new URL("http://book.qq.com/s/book/0/15/15722/2.shtml");
          URLConnection connection
          =url.openConnection();
          InputStream ips
          =connection.getInputStream();
          String filename
          =url.getFile();
          println(filename)
          FileOutputStream fos
          =new FileOutputStream("D:\\07_his\\test.txt");
          String line
          =System.getProperty("line.separator");
          println 
          "主機名:"+url.getHost()
          println 
          "授權::"+url.getAuthority()
          println 
          "文件名:"+url.getFile()
          println 
          "端口號:"+url.getDefaultPort()
          println 
          "Type: "+connection.getContentType()
          println 
          "長度:"+connection.getContentLength()
           def data;
           
          while((data=ips.read())!=-1)
           
          {
            fos.write(data);
           }

           ips.close();
           fos.close();
                                  

           

           

          posted on 2009-01-03 22:12 圣潔王子 閱讀(377) 評論(0)  編輯  收藏 所屬分類: Groovy

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


          網站導航:
           
          主站蜘蛛池模板: 嘉兴市| 大城县| 台中市| 永宁县| 平泉县| 镇远县| 丹棱县| 焦作市| 平安县| 太康县| 曲周县| 林西县| 徐闻县| 黄骅市| 大悟县| 洱源县| 莲花县| 淳化县| 耿马| 门头沟区| 大悟县| 伊金霍洛旗| 临澧县| 安福县| 徐闻县| 金湖县| 辽宁省| 玛纳斯县| 鄂温| 澄江县| 白城市| 碌曲县| 赞皇县| 奉贤区| 南开区| 鄂伦春自治旗| 辉南县| 米易县| 平罗县| 屯门区| 博兴县|