使用下面的代碼從互聯網下載rar文件時,下載的文件比實際大。 不確定是什麼原因造成的?Java:使用BufferedInputStream,BufferedOutputStream下載問題
bis = new BufferedInputStream(urlConn.getInputStream());
bos = new BufferedOutputStream(new FileOutputStream(outputFile));
eventBus.fireEvent(this, new DownloadStartedEvent(item));
int read;
byte[] buffer = new byte[2048];
while ((read = bis.read(buffer)) != -1) {
bos.write(buffer);
}
eventBus.fireEvent(this, new DownloadCompletedEvent(item));
yes流在finally塊中關閉,但爲了簡潔起見沒有粘貼。看看公用事業,非常有趣 – nkr1pt 2010-04-23 19:37:46