調用遠程接口,返回的是http文件流,打開相關url,就可以直接下載txt文件,
要對這相關的文件內容進行操作,不保存,可以調用下面這個方法直接讀取文件流內容,測試了下,是可以的
public String getYCFile(String urlPath) { - String readStr = "";
- try {
- try {
- String strUrl = urlPath.trim();
- URL url = new URL(strUrl);
- HttpURLConnection urlCon = (HttpURLConnection) url.openConnection();
- urlCon.setConnectTimeout(10000);
- urlCon.setReadTimeout(30000);
- BufferedReader in = new BufferedReader(new InputStreamReader(
- urlCon.getInputStream(), "GBK"));
- String inputLine = " ";
- while ((inputLine = in.readLine()) != null) {
- readStr += inputLine.trim();
- }
- in.close();
- return readStr;
- } catch (IOException e) {
- readStr = "";
- }
- } catch (Exception e) {
- readStr = "";
- }
- return readStr;
- }
posted on 2015-03-06 15:40
藤本薔薇 閱讀(1073)
評論(0) 編輯 收藏