copying resource to sdcard gives a damaged file in android
<p>I am trying to move a raw resource (it is a zip file) from the app to SD card using this code:</p>

<pre><code>void copyFile() throws IOException {
    File dest = Environment.getExternalStorageDirectory();
    InputStream in = context.getResources().openRawResource(R.raw.file);
    OutputStream out = new FileOutputStream(dest + "/file.zip");

    // Transfer bytes from in to out
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) &gt; 0) {
        out.write(buf, 0, len);
    }
    in.close();
    out.close();
}
</code></pre>

<p>However, when I check the file on the sd card I get the message:
"The archive is either in an unknown format or damaged"</p>

<p>Why is the file not being copied properly?</p>
