我想下载一个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;
}
哪条线指向异常的原因?你不应该忽略这样的有用信息! – polygenelubricants 2010-05-02 16:50:05
@polygenelubricants:你在开玩笑吧?让我们猜测是最好的部分! – 2010-05-02 16:51:57
您是否看过您的数据并查看它是否有任何无效字符?你可能想要简化你的代码并去掉任何与流无关的东西。尝试将您的输入回显到输出文件并查看您获得的内容。 – 2010-05-02 16:53:41