我正在尝试使用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;
}
答案 0 :(得分:1)
尝试使用分块流模式。
答案 1 :(得分:0)
问题可能是您的应用程序运行速度快于检索输入数据