Java: downloading issue using BufferedInputStream, BufferedOutputStream

Posted by nkr1pt on Stack Overflow See other posts from Stack Overflow or by nkr1pt
Published on 2010-04-23T19:09:37Z Indexed on 2010/04/23 19:13 UTC
Read the original article Hit count: 293

Filed under:
|

When downloading a rar file from the internet with the code below, the downloaded file is larger than it actually is. Not sure what causes this?

        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));

© Stack Overflow or respective owner

Related posts about java

Related posts about downloading