【发布时间】:2010-05-02 16:48:33
【问题描述】:
我正在尝试使用 Stream 下载一个 xml 文件,一切都很好,直到 xml 大小变得大于 9 MB,所以我遇到了这个错误 java.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;
}
【问题讨论】:
-
哪一行被指出为异常的原因?您不应该省略诸如此类的有用信息!
-
@polygenelubricants:你在开玩笑吗?让我们猜测是最好的部分!
-
您是否查看了您的数据并查看其中是否包含任何无效字符?您可能希望简化代码并删除与流无关的任何内容。尝试将您的输入回显到输出文件,看看您得到了什么。
-
您的 XML 文件中是否有可能存在 EOF character?或者可能是一些编码问题?还是大数据文件只是连接了 2 个稍小的文件(哪个有效)?
标签: java