title: How to copy files in Android from sdcard to internal storage without corrupting them
body: <p>My program needs to copy two files (.ogg sound files) located in a folder in sd card to cache dir of the application which is returned via getCacheDir() </p>
  
  <p>i use the following code to copy the files </p>
  
  <pre><code>File cache=this.getCacheDir();
  cache.mkdirs();
  fout=new FileOutputStream(cache.getAbsolutePath()+"/file1.ogg");
  fin=new FileInputStream(Environment.getExternalStorageDirector+"/imported/file1.ogg");
  
  byte[] buf = new byte[128];
  int len;
  while ((len = fin.read(buf,0,128))&gt;-1){
      fout.write(buf, 0, len);
  }
  
  fout.close();
  fin.close();    
  </code></pre>
  
  <p>the code compiles and runs without any error, both files are copied and have the same size as their original files,
   but when my program tries to play those .ogg files IO exception occurs also when i try to play the copied files in my pc they produce error.</p>
  
  <p>however if i copy them from one to another folder on the sd card it plays fine.
  that means copying from external to external media is ok but from external to internal is causing corruption!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here is what I found from my experiment and observations:</p>
  
  <p>A) copying original file programatically to internal storage -> fails to play file</p>
  
  <p>B) copying original file directly to internal storage (I have root access) -> plays fine</p>
  
  <p>C) copying the programmatically copied files directly back to anywhere in sd card -> plays fine again (AMAZING!)</p>
  
  <p>NOTE:-here copying directly means using copy paste from Android OS</p>
  
  <p>to my sense somehow the copied file doesn't work just after copying it , but once it is moved to sd card it starts working again.</p>
  
  <p><strong>FTW man!</strong></p>