如何将.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);
}
}
答案 0 :(得分:1)
mSavePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
File file = new File(mSavePath+"/filename.mp3");