Android: No such file or directory found error?

浪尽此生 提交于 2019-12-23 03:28:09

问题


I'm playing and recording an audio simultaneously in order to perform audio matching analysis using musicg API. I'm getting the following error/s everytime I run my app:

V/playRecordAudio: Playing sound & recording stopped
 W/System.err: java.io.FileNotFoundException: /storage/emulated/0: open failed: EISDIR (Is a directory)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:452)
W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:127)
W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:116)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment.copyWaveFile(SpeakersFragment.java:316)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment.stopRecording(SpeakersFragment.java:284)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment.access$200(SpeakersFragment.java:45)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment$3.onCompletion(SpeakersFragment.java:176)
W/System.err:     at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:2821)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err:     at android.os.Looper.loop(Looper.java:148) 
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5417)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
W/System.err: Caused by: android.system.ErrnoException: open failed: EISDIR (Is a directory)
W/System.err:     at libcore.io.Posix.open(Native Method)
W/System.err:     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:438)
W/System.err:   ... 14 more
W/System.err: java.io.FileNotFoundException: /storage/emulated/0/AudioRecorder/1491446370522.wav: open failed: ENOENT (No such file or directory)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:452)
W/System.err:     at java.io.FileInputStream.<init>(FileInputStream.java:76)
W/System.err:     at java.io.FileInputStream.<init>(FileInputStream.java:103)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment.getScore(SpeakersFragment.java:399)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment.stopRecording(SpeakersFragment.java:285)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment.access$200(SpeakersFragment.java:45)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment$3.onCompletion(SpeakersFragment.java:176)
W/System.err:     at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:2821)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err:     at android.os.Looper.loop(Looper.java:148)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5417)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
 W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
W/System.err: Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
W/System.err:     at libcore.io.Posix.open(Native Method)
W/System.err:     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:438)
W/System.err:   ... 13 more
I/System.out: 0.0
W/MediaPlayer: mediaplayer went away with unhandled events

I'm trying to save the recording to a file and then pass it to getScore() method in order to compare it to the original audio file played and return a matching score. Below is the relevant code in my MainActivity with the lines giving the error in bold.

EDIT 1:

String mFileName = getFilename();
...
private void stopRecording() {
            if (null != recorder) {
                isRecording = false;

                int i = recorder.getState();
                if (i == 1)
                    recorder.stop();
                recorder.release();

                recorder = null;
                recordingThread = null;
            }

            copyWaveFile(getTempFilename(), mFileName);
            getScore(); //error here
            deleteTempFile();
        }

public void getScore (){

            String fileName1 = mFileName;
            String fileName2 = "R.raw.forrest_gump_theme"; //Need to change this

            try {
                //InputStream fis1 = null, fis2 = null;
                InputStream fis1, fis2;
                fis1 = new FileInputStream(fileName1);//error here
                fis2 = new FileInputStream(fileName2);

                Wave wave1 = new Wave(fis1), wave2 = new Wave (fis2);
                FingerprintSimilarity similarity;

                similarity = wave1.getFingerprintSimilarity(wave2);
                result = similarity.getSimilarity()*100;


            }catch (Exception e){
                e.printStackTrace();
            }
            System.out.println(result);
        }

回答1:


I think the problem is in copyWaveFile():

You are sending mFileName variable to copyWaveFile() but changing its path using following code:

 outFilename = Environment.getExternalStorageDirectory().getPath();

Try removing above line and check once again. Let me know if same error persists.



来源:https://stackoverflow.com/questions/43244923/android-no-such-file-or-directory-found-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!