java.io.FileNotFoundException:打开失败:EISDIR(是一个目录)
我正试图在android studio中的钢琴应用程序中使用java.io.FileNotFoundException:打开失败:EISDIR(是一个目录),java,android,Java,Android,我正试图在android studio中的钢琴应用程序中使用MediaRecorder录制音频。在搜索关于如何将文件另存为getExternalPublicDirectory的答案后,不推荐使用context.getExternalFilesDir(null).getAbsolutePath()。现在,当我运行应用程序并点击录制按钮时,在mediaRecorder.prepare()行中出现以下错误java.io.FileNotFoundException:open failed:EISDIR(
MediaRecorder
录制音频。在搜索关于如何将文件另存为getExternalPublicDirectory
的答案后,不推荐使用context.getExternalFilesDir(null).getAbsolutePath()代码>。现在,当我运行应用程序并点击录制按钮时,在mediaRecorder.prepare()行中出现以下错误java.io.FileNotFoundException:open failed:EISDIR(是一个目录)
代码>。。请帮忙
private void startRecording() throws IOException {
try {
String path = context.getExternalFilesDir(null).getAbsolutePath();
audioFile = new File(path);
} catch (Exception e) {
Log.e("Error Tag", "external storage access error " + e.getMessage());
return;
}
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setOutputFile(audioFile.getAbsolutePath());
mediaRecorder.prepare();
mediaRecorder.start();
获取java.io.FileNotFoundException:open失败:EISDIR(是一个目录)
是预期的,因为您提供给setOutputFile()
的路径指向一个目录,而不是一个保存记录数据的文件
问题很清楚,
设置要生成的输出文件的路径
试着修好你的路
String dirPath = context.getExternalFilesDir(null).getAbsolutePath();
String filePath = direPath + "/recording";
audioFile = new File(filePath);
获取java.io.FileNotFoundException:open失败:EISDIR(是一个目录)
是预期的,因为您提供给setOutputFile()
的路径指向一个目录,而不是一个保存记录数据的文件
问题很清楚,
设置要生成的输出文件的路径
试着修好你的路
String dirPath = context.getExternalFilesDir(null).getAbsolutePath();
String filePath = direPath + "/recording";
audioFile = new File(filePath);