隨筆-71  評論-5  文章-0  trackbacks-0

          1. 調用遠程接口,返回的是http文件流,打開相關url,就可以直接下載txt文件,
            要對這相關的文件內容進行操作,不保存,可以調用下面這個方法直接讀取文件流內容,測試了下,是可以的




            public
             String getYCFile(String urlPath) {  
          2.         String readStr = "";  
          3.         try {  
          4.             try {  
          5.                 String strUrl = urlPath.trim();  
          6.                 URL url = new URL(strUrl);  
          7.                 HttpURLConnection urlCon = (HttpURLConnection) url.openConnection();  
          8.                 urlCon.setConnectTimeout(10000);  
          9.                 urlCon.setReadTimeout(30000);  
          10.                 BufferedReader in = new BufferedReader(new InputStreamReader(  
          11.                         urlCon.getInputStream(), "GBK"));  
          12.                 String inputLine = " ";  
          13.                 while ((inputLine = in.readLine()) != null) {  
          14.                     readStr += inputLine.trim();  
          15.                 }  
          16.                 in.close();  
          17.                 return readStr;  
          18.             } catch (IOException e) {  
          19.                 readStr = "";  
          20.             }  
          21.         } catch (Exception e) {  
          22.             readStr = "";  
          23.         }  
          24.         return readStr;  
          25.     } 
          posted on 2015-03-06 15:40 藤本薔薇 閱讀(1074) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 略阳县| 宁河县| 望谟县| 遵义市| 苍溪县| 丽水市| 鹤庆县| 平利县| 罗城| 成都市| 临武县| 汝阳县| 来安县| 额敏县| 噶尔县| 钟祥市| 金昌市| 阳山县| 沁源县| 区。| 宁国市| 炉霍县| 昭苏县| 莆田市| 惠水县| 鄂伦春自治旗| 观塘区| 新竹市| 哈尔滨市| 河北省| 伊金霍洛旗| 舞钢市| 长泰县| 常州市| 新昌县| 定州市| 沁源县| 平武县| 兴义市| 昌吉市| 长寿区|