gpt4 book ai didi

java.io.FileNotFoundException : open failed: EISDIR (Is a directory) 错误

转载 作者:行者123 更新时间:2023-12-05 02:53:40 26 4
gpt4 key购买 nike

我正在尝试使用 MediaRecorder 在 android studio 的 Piano 应用程序中录制音频。在搜索有关如何将文件保存为 getExternalPublicDirectory 已弃用的答案后,我使用了 context.getExternalFilesDir(null).getAbsolutePath(); 。现在,当我运行该应用程序并点击录制按钮时,我在 mediaRecorder.prepare(); 行中收到此错误 java.io.FileNotFoundException: open failed: EISDIR (Is a directory) .. 请帮忙!!

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 failed: EISDIR (Is a directory) 是预期的,因为您提供给 setOutputFile() 的路径指向 < strong>到一个目录而不是一个文件来保存记录的数据。

documentation很清楚,

Sets the path of the output file to be produced.

尝试修复你的路径,

String dirPath = context.getExternalFilesDir(null).getAbsolutePath();
String filePath = direPath + "/recording";
audioFile = new File(filePath);

关于java.io.FileNotFoundException : open failed: EISDIR (Is a directory) 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62101194/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com