2012-02-28 292 views
1

我需要从应用程序下载文件。我有一个原始文件夹中的5个音频文件。在一个按钮的onclick事件中,我需要从5个文件中选择一个音频文件并将其下载到SD卡。 我该如何实现这个目标?将音频文件从原始文件夹下载到SD卡

+0

就像将一个普通的音频文件保存到SD卡一样。或者为这种情况下的任何文件。 – Warpzit 2012-02-28 10:00:56

+0

感谢plz发送一个链接上该PLZ – Goofy 2012-02-28 10:03:28

+1

http://stackoverflow.com/questions/4509877/android-dev-help-saving-an-image-from-res-raw-or-asset-folder-to-the- SD卡,这可能是有帮助的 – Triode 2012-02-28 10:03:53

回答

1

这是如此简单,但mistakefull ......试试这个代码:

  File directoryTest = new File(
       Environment.getExternalStorageDirectory(), "raw2sd"); 
      try { 
       //coping sound file to sd 
       //defining specific directory 
       File soundDir = new File(directoryTest, "ORG"); 
       //making directories 
       soundDir.mkdirs(); 
       FileOutputStream sound = new FileOutputStream(
         soundDir.getPath() + "/soundName.mp3"); 
       InputStream is = getResources().openRawResource(R.raw.soundFile); 
       int a = is.available(); 
       byte[] buf = new byte[a]; 
       is.read(buf, 0, a); 
       sound.write(buf); 
       sound.flush(); 
       sound.close(); 
      } catch (FileNotFoundException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
       return false; 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
       return false; 
      } 

,这是100%测试。

相关问题