调用远程接口,返回的是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
藤本蔷薇 阅读(1068)
评论(0) 编辑 收藏