Counted bytes and total bytes differ
<p>I'm writing an Android application which copies files from the assets to one file on the device's drive (no permission problems, bytes get from the assets to the drive). The file that I need to copy is larger than 1 MB, so I split it up into multiple files, and I copy them with something like:</p>

<pre><code>try {
    out = new FileOutputStream(destination);
    for (InputStream file : files /* InputStreams from assets */) {
        copyFile(file);
        file.close();
    }
    out.close();
    System.out.println(bytesCopied); // shows 8716288
    System.out.println(new File(destination).length()); // shows 8749056
} catch (IOException e) {
    Log.e("ERROR", "Cannot copy file.");
    return;
}
</code></pre>

<p>Then, the <code>copyFile()</code> method:</p>

<pre><code>private void copyFile(InputStream file) throws IOException {
    byte[] buffer = new byte[16384];
    int length;
    while ((length = file.read(buffer)) &gt; 0) {
        out.write(buffer);
        bytesCopied += length;
        out.flush();
    }
}
</code></pre>

<p>The correct number of total bytes that the destination file should contain is 8716288 (that's what I get when I look at the original files and if I count the written bytes in the Android application), but <code>new File(destination).length()</code> shows 8749056.</p>

<p>What am I doing wrong?</p>
