2010-05-02 88 views
0

我想下载一个XML文件使用流和事情都很好,直到xml大小变得比9 MB大,所以我有这个错误 java.io.IOException:过早的EOFjava.io.IOException:早熟EOF

这是代码

BufferedInputStream bfi = null; 
     try { 
      bfi = new BufferedInputStream(new URL("The URL").openStream()); 
      String name = "name.xml"; 
      FileOutputStream fb = new FileOutputStream(name); 
      BufferedOutputStream bout = new BufferedOutputStream(fb, 1024); 
      byte[] data = new byte[1024]; 
      int x = 0; 
      while ((x = bfi.read(data, 0, 1024)) >= 0) { 
       bout.write(data, 0, x); 
      } 
      this.deletePhishTankDatabase(this.recreateFileName()); 
      ptda.insertDownloadTime(hour, day, month, year); 
      bout.close(); 
      bfi.close(); 
     } catch (IOException ex) { 
      Logger.getLogger(PhishTankDataBase.class.getName()).log(Level.SEVERE, null, ex); 
     } finally { 
      try { 
       bfi.close(); 
      } catch (IOException ex) { 
       Logger.getLogger(PhishTankDataBase.class.getName()).log(Level.SEVERE, null, ex); 
      } 
     } 
    } else { 
     System.out.println("You can't do anything"); 
     return; 
    } 
+1

哪条线指向异常的原因?你不应该忽略这样的有用信息! – polygenelubricants 2010-05-02 16:50:05

+0

@polygenelubricants:你在开玩笑吧?让我们猜测是最好的部分! – 2010-05-02 16:51:57

+0

您是否看过您的数据并查看它是否有任何无效字符?你可能想要简化你的代码并去掉任何与流无关的东西。尝试将您的输入回显到输出文件并查看您获得的内容。 – 2010-05-02 16:53:41

回答

0

的问题可能是您的应用程序运行速度比它检索输入数据

+1

编号读取块,除非有EOF。 – extraneon 2010-05-02 17:01:50

+0

读取块直到数据或EOS到达。 – EJP 2010-05-03 00:26:09

1

尝试使用分块流模式。