title: Android FileOutputStream creates corrupted file
body: <p>I have an app that creates multiple files using a byte array it gets from a Socket InputStream. The file saves perfectly when I just save one file, but if I save the one file then re-instantiate the file stream and save a different file, the first file gets corrupted and the second file is saved perfectly. I opened the two files in a text editor and it seems (about...)the first 1/5th of the first file is blank spaces but the second file is full, and they both have the same size properties(9,128,731 bytes). The following example is a duplication of the senario but with the same corruption result:</p>
  
  <pre><code>FileOutputStream outStream;
  outStream = new FileOutputStream("/mnt/sdcard/testmp3.mp3");
  File file = new File("/mnt/sdcard/test.mp3");
  FileInputStream inStream = new FileInputStream(file);
  byte[] buffer = new byte[9128731];
  inStream.read(buffer);
  outStream.write(buffer, 0, buffer.length);
  inStream.close();
  outStream.flush();
  outStream.close();
  outStream = null;
  outStream = new FileOutputStream("/mnt/sdcard/testmp32.mp3");
  outStream.write(buffer, 0, buffer.length);
  inStream.close();
  outStream.flush();
  outStream.close();
  outStream = null;
  </code></pre>
  
  <p>I tried this EXACT code in a regular java application and both files were saved without a problem. Does anyone know why the android is doing this?</p>
  
  <p>Any help would be GREATLY appreciated</p>