我正在开发一个Android应用程序,其中一部分会录制音频。 我的代码工作正常,它使用以下代码将录制的音频保存在SD卡中:
String mediaFile = null;
mediaFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myRecordings.mp3";
但我想创建一个包含应用名称的文件夹,并能够将录制的音频保存到该文件夹中。 有人能告诉我该怎么做吗?我成功创建了文件夹,但我不知道如何在那里移动mediaFile:
String newFolder = "/FolderName";
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File myNewFolder = new File(extStorageDirectory + newFolder);
myNewFolder.mkdir();
mediaFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myRecordings.mp3"
感谢任何帮助。感谢
答案 0 :(得分:1)
只需将该文件夹添加到路径即可。像这样:
String sep = File.separator; // Use this instead of hardcoding the "/"
String newFolder = "FolderName";
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File myNewFolder = new File(extStorageDirectory + sep + newFolder);
myNewFolder.mkdir();
mediaFile = Environment.getExternalStorageDirectory().toString()
+ sep + newFolder + sep + "myRecordings.mp3";