Android: 找不到这样的文件或目录错误?

Android: No such file or directory found error?

我正在同时播放和录制音频,以便使用 musicg API 执行音频匹配分析。每次我 运行 我的应用程序时,我都会收到以下 error/s:

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.access0(SpeakersFragment.java:45)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment.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.access0(SpeakersFragment.java:45)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment.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

我正在尝试将录音保存到文件中,然后将其传递给 getScore() 方法,以便将其与播放的原始音频文件和 return 匹配的乐谱进行比较。下面是我的 MainActivity 中的相关代码,其中以粗体显示错误的行。

编辑 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);
        }

我认为问题出在 copyWaveFile():

您正在将 mFileName 变量发送到 copyWaveFile() 但使用以下代码更改其路径:

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

尝试删除上面的行并再次检查。如果同样的错误仍然存​​在,请告诉我。