隨筆-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 藤本薔薇 閱讀(1076) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 将乐县| 晋中市| 南部县| 长春市| 和平区| 临夏县| 师宗县| 东乌珠穆沁旗| 双鸭山市| 个旧市| 同仁县| 长乐市| 延津县| 开江县| 革吉县| 清远市| 米泉市| 武邑县| 乌兰县| 米脂县| 贵州省| 镇康县| 红安县| 土默特右旗| 大港区| 封丘县| 绥中县| 元谋县| 繁昌县| 阳春市| 昔阳县| 县级市| 怀宁县| 渝北区| 和政县| 西藏| 武邑县| 正阳县| 贞丰县| 尉犁县| 盘锦市|