Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

I am trying to record audio in my Piano app in android studio using MediaRecorder. After searching for answers on how to save the file as getExternalPublicDirectory is deprecated so i used context.getExternalFilesDir(null).getAbsolutePath(); . Now when i run the app and hit the record button , i get this error java.io.FileNotFoundException: open failed: EISDIR (Is a directory) in the line mediaRecorder.prepare(); .. Please Help!!

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();
like image 256
Arnab Avatar asked Nov 01 '25 15:11

Arnab


1 Answers

Getting java.io.FileNotFoundException: open failed: EISDIR (Is a directory) is what expected since the path that you're providing to setOutputFile() points to a directory and not a file to save the recorded data.

The documentation is clear,

Sets the path of the output file to be produced.

Try and fix your path,

String dirPath = context.getExternalFilesDir(null).getAbsolutePath();
String filePath = direPath + "/recording";          
audioFile = new File(filePath);
like image 146
Themelis Avatar answered Nov 03 '25 07:11

Themelis