調(diào)用遠(yuǎn)程接口,返回的是http文件流,打開相關(guān)url,就可以直接下載txt文件,
要對這相關(guān)的文件內(nèi)容進(jìn)行操作,不保存,可以調(diào)用下面這個方法直接讀取文件流內(nèi)容,測試了下,是可以的
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
藤本薔薇 閱讀(1076)
評論(0) 編輯 收藏