如何将.mp3文件保存到sdCard上的“音乐”目录中。

以下代码始终将文件保存到没有任何扩展名的downloads文件夹中

   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);
    }
     }

最佳答案

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

09-05 18:07