Saving a file to the external temp dir from R.raw.some_file.m4a
<p>I need to be able to save a file to the external storgage temp dir. The file I am saving though is the R.raw directory of my app.  </p>

<p>I have used this example here.
<a href="http://stackoverflow.com/questions/6979521/move-raw-file-to-sd-card-in-android">Move Raw file to SD card in Android</a></p>

<p>The issue is 
1. The app seems to read the .m4a file I want (possible reads the bytes wrong here).
2. When the file is saved to the /tmp dir the file size is totally wrong. 
eg one file goes from 30kb to 300kb, another goes from 25kb, to .25kb. </p>

<p>Any suggestions</p>

<pre><code>public String saveAs(int ressound, String whipName){  

     byte[] buffer=null;  
     InputStream fIn = getBaseContext().getResources().openRawResource(ressound);  
     int size=0;  

     try {  
      size = fIn.available();  
      buffer = new byte[size];  
      fIn.read(buffer);  
      fIn.close();  
     } catch (IOException e) {  
      // TODO Auto-generated catch block
         Log.i("saveas", "did not save1");
      //return false;  
     }  

     String path= Environment.getExternalStorageDirectory().getAbsolutePath()+"/tmp/.pw2";
     String filename="/"+whipName+".m4a";  
     Log.i("path", "file path is " + path);
     boolean exists = (new File(path)).exists();  
     if (!exists){new File(path).mkdirs();}  

     FileOutputStream save;  
     try {  
      save = new FileOutputStream(path+filename);  
      save.write(buffer);  
      save.flush();  
      save.close();  
     } catch (FileNotFoundException e) {  
      // TODO Auto-generated catch block  
         Log.i("saveas", "did not save2");
         //return false;  
     } catch (IOException e) {  
      // TODO Auto-generated catch block
         Log.i("saveas", "did not save3");
      //return false;  
     }      

     File k = new File(path, filename);  

     return  k.getAbsolutePath();
}
</code></pre>
