在Sd Card Android上的音乐目录中保存文件

时间:2014-01-11 04:05:16

标签: java android cordova

如何将.mp3文件保存到sdCard上的Music目录。

以下代码始终将文件保存到下载文件夹,不带任何扩展名

   private FileOutputStream getOutStream(String fileName) throws FileNotFoundException{
    if (Environment.getExternalStorageState().equals(
            Environment.MEDIA_MOUNTED)) {
        String sdpath = Environment.getExternalStorageDirectory()
                + "/";
        mSavePath = sdpath + "download";
        File file = new File(mSavePath);

        if (!file.exists()) {
            file.mkdir();
        }
        File saveFile = new File(mSavePath, fileName);
        return new FileOutputStream(saveFile);
        }else{
        mSavePath = mContext.getFilesDir().getPath();
        return mContext.openFileOutput(fileName ,          Context.MODE_WORLD_READABLE);
    }
     } 

1 个答案:

答案 0 :(得分:1)

 mSavePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
 File file = new File(mSavePath+"/filename.mp3");