java.io.FileNotFoundException:打开失败:EISDIR(是一个目录)

java.io.FileNotFoundException:打开失败:EISDIR(是一个目录),java,android,Java,Android,我正试图在android studio中的钢琴应用程序中使用MediaRecorder录制音频。在搜索关于如何将文件另存为getExternalPublicDirectory的答案后,不推荐使用context.getExternalFilesDir(null).getAbsolutePath()。现在,当我运行应用程序并点击录制按钮时,在mediaRecorder.prepare()行中出现以下错误java.io.FileNotFoundException:open failed:EISDIR(

我正试图在android studio中的钢琴应用程序中使用
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);