【问题标题】:URLConnection didnt return complete content of fileURLConnection 没有返回文件的完整内容
【发布时间】:2015-07-22 21:24:56
【问题描述】:

我的代码看起来像

    URL oracle = new URL(calURL);    
FileWriter overall = new FileWriter("overall.txt");    
    HttpURLConnection yc = (HttpURLConnection) oracle.openConnection();
    BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null) {

   overall.append("\n"+inputLine);

    }

它似乎只返回了一半的内容.. 没有得到完整的内容

注意:calURL 是动态生成的

【问题讨论】:

  • 您在 while 循环中编写的代码是什么?
  • 我只是将内容转储到 txt 文件中。
  • 你调试过你的代码吗?在将断点写入文件之前应用断点?
  • 文件大小超过 40 MB。它有很多行。它适用于 60% 的内容,然后退出 while 循环。所以我没有做调试,
  • 有错误吗?用 try-catch 包围整个操作。

标签: java httpurlconnection


【解决方案1】:

calURL 需要很长时间才能加载。我猜在我的流开始阅读之前。我在 URL 连接之前包含了超时,它现在正在获取完整数据。

【讨论】:

  • 所以你有超时异常并没有说出来?
  • 不,我没有得到任何异常。
猜你喜欢
  • 2015-04-07
  • 2014-06-17
  • 1970-01-01
  • 1970-01-01
  • 2013-11-26
  • 2011-09-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多