简体   繁体   中英

Save File in Music Directory on Sd Card Android

How do i save a .mp3 file to the Music directory on the sdCard.

The code below always saves the file to the downloads folder without any extensions

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM