随笔-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 藤本蔷薇 阅读(1059) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: