【问题标题】:java.io.FileNotFoundException: open failed: EISDIR (Is a directory)java.io.FileNotFoundException:打开失败:EISDIR(是一个目录)
【发布时间】:2020-05-30 18:48:46
【问题描述】:

我正在尝试使用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 android


    【解决方案1】:

    获取java.io.FileNotFoundException: open failed: EISDIR (Is a directory) 是预期的结果,因为您提供给setOutputFile() 的路径指向指向目录,而不是用于保存记录数据的文件。

    documentation 很清楚,

    设置要生成的输出文件的路径。

    尝试修复你的路径,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-02
      • 1970-01-01
      相关资源
      最近更新 更多