Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在原始文件夹中获取字符串文件名(我的音频文件)_Java_Android - Fatal编程技术网

Java 如何在原始文件夹中获取字符串文件名(我的音频文件)

Java 如何在原始文件夹中获取字符串文件名(我的音频文件),java,android,Java,Android,我想获取原始文件夹中音频文件的字符串文件名。原因是我想在cheapSoundFile类中使用该文件名,如下所示cheapSoundFile fileRecord=cheapSoundFile.create(pathFile,listener)结果是一个数字,如下图所示 这是我的密码: public class EvalActivity extends AppCompatActivity { TextView title, lainlain, hammingWindow, frameGa

我想获取原始文件夹中音频文件的字符串文件名。原因是我想在cheapSoundFile类中使用该文件名,如下所示
cheapSoundFile fileRecord=cheapSoundFile.create(pathFile,listener)结果是一个数字,如下图所示

这是我的密码:

public class EvalActivity extends AppCompatActivity {

    TextView title, lainlain, hammingWindow, frameGained;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_eval);

        title = findViewById(R.id.textView);
        lainlain = findViewById(R.id.textView2);
        hammingWindow = findViewById(R.id.hammingWindow);
        frameGained = findViewById(R.id.frame_gained);

        Intent intent = getIntent();
        String pathFile = intent.getStringExtra("filepath");
        title.setText(pathFile);


        final CheapSoundFile.ProgressListener listener = new CheapSoundFile.ProgressListener() {

            @Override
            public boolean reportProgress(double fractionComplete) {
                return true;
            }
        };
        try {
            CheapSoundFile fileRecord = CheapSoundFile.create(pathFile, listener);
            int[] frameGainsRecord = fileRecord.getFrameGains();

            // TODO read audio file below here
            CheapSoundFile fileSource = CheapSoundFile.create(
                    Uri.parse("android.resource://com.latihcoding.iqro/" + R.raw.abaa).toString(),
                    listener
            );

            int numFrame = fileRecord.getNumFrames();
            int samplePerFrame = fileRecord.getSamplesPerFrame();
            int sumFrameGainsRecord = 0;
            int i;
            for (i = 0; i < frameGainsRecord.length; i++){
                sumFrameGainsRecord += frameGainsRecord[i];
            }

            int [] frameRecord = fileRecord.getFrameLens();

            Log.v("Evaluation","fileLoadDone");
            int freqs = fileRecord.getSampleRate();
            int sampleRateAbaa = fileSource.getSampleRate();
            String frequency =  "Sample rate = " + freqs + "\ngetFrameLens return array"
                    + myJoin(frameRecord, ",");
            frequency += " getFrameLens length = " + frameRecord.length + " numframe " + numFrame;
            frequency += " sample per frame " + samplePerFrame + " getFrameGains " + frameGainsRecord.length;
            frequency += " total frame gains record " + sumFrameGainsRecord + " dan nilai i = " + i;
            frequency += "\ngetFrameGains return array\n" + myJoin(frameGainsRecord, ",");
            frequency += " hasil hamming window dibawah ini menggunakan panjang dari numframe \n";
            lainlain.setText(frequency);

            String audioRawFolder = "" + sampleRateAbaa;
            hammingWindow.setText(audioRawFolder);

        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String myJoin(int[] arr, String separator) {
        if (null == arr || 0 == arr.length) return "";

        StringBuilder sb = new StringBuilder(256);
        sb.append(arr[0]);

        //if (arr.length == 1) return sb.toString();

        for (int i = 1; i < arr.length; i++) sb.append(separator).append(arr[i]);

        return sb.toString();
    }

    public static String myJoin(float[] arr, String separator) {
        if (null == arr || 0 == arr.length) return "";

        StringBuilder sb = new StringBuilder(256);

        sb.append(arr[0]);

        //if (arr.length == 1) return sb.toString();

        for (int i = 1; i < arr.length; i++) sb.append(separator).append(arr[i]);

        return sb.toString();
    }
}
但该代码会产生错误FileNotFoundExeption,请参见下图: . 我也试过了,我把代码(在try块中)改成这样

InputStream stream = getResources().openRawResource(R.raw.abaa);
// TODO read audio file from raw folder below here
            byte[] buffer = new byte[stream.available()];
            stream.read(buffer);
            stream.close();
            String fileSourcePath = new String(buffer, "UTF-8");
            CheapSoundFile fileSource = CheapSoundFile.create(fileSourcePath, listener);
结果是:

 W/System.err: java.io.FileNotFoundException: RIFF�/��WAVEfmt �������������������������data�/�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
W/System.err: ��
W/System.err: ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������    ��  ��  ��  ��  ��  ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
W/System.err: ��
W/System.err: ���*�*�6�6�B�B�L�L�W�W�f�f�t�t�������������������������������������+�+�?�?�R�R�g�g�{�{�������������������������������������+��+��<��<��P��P��e��e��y��y��������������������������������������������''77EETTaapp������������((22;;DDLLRRYY__bbhhppvv}}��������������������������������������������������������������������������������������������������������{{wwqqjjffbb\\XXTTLLDD??<<995511--&&��������������������������������{{wwqqii^^PPAA44++%%  ����������������������������������������������������������������������������������������������{��{��p��p��d��d��\��\��U��U��Q��Q��N��N��G��G��?��?��9��9��2��2��*��*��%��%��������������������������������������������������������������������������������������z�z�k�k�[�[�K�K�9�9�(�(���������������������������
W/System.err:     at com.latihcoding.hendriktekayadiskoringkaraoke.soundfile.CheapSoundFile.create(CheapSoundFile.java:52)
W/System.err:     at com.latihcoding.hendriktekayadiskoringkaraoke.EvalActivity.onCreate(EvalActivity.java:51)
W/System.err:     at android.app.Activity.performCreate(Activity.java:5447)
W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
W/System.err:     at android.app.ActivityThread.access$800(ActivityThread.java:166)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err:     at android.os.Looper.loop(Looper.java:136)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5590)
W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096)
W/System.err:     at dalvik.system.NativeStart.main(Native Method)
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@420c0bc8 time:3328964
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@42040820 time:3328965
W/System.err:java.io.FileNotFoundException:RIFF�/��波峰�������������������������数据�/����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������?
 W/System.err: java.io.FileNotFoundException: RIFF�/��WAVEfmt �������������������������data�/�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
W/System.err: ��
W/System.err: ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������    ��  ��  ��  ��  ��  ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
W/System.err: ��
W/System.err: ���*�*�6�6�B�B�L�L�W�W�f�f�t�t�������������������������������������+�+�?�?�R�R�g�g�{�{�������������������������������������+��+��<��<��P��P��e��e��y��y��������������������������������������������''77EETTaapp������������((22;;DDLLRRYY__bbhhppvv}}��������������������������������������������������������������������������������������������������������{{wwqqjjffbb\\XXTTLLDD??<<995511--&&��������������������������������{{wwqqii^^PPAA44++%%  ����������������������������������������������������������������������������������������������{��{��p��p��d��d��\��\��U��U��Q��Q��N��N��G��G��?��?��9��9��2��2��*��*��%��%��������������������������������������������������������������������������������������z�z�k�k�[�[�K�K�9�9�(�(���������������������������
W/System.err:     at com.latihcoding.hendriktekayadiskoringkaraoke.soundfile.CheapSoundFile.create(CheapSoundFile.java:52)
W/System.err:     at com.latihcoding.hendriktekayadiskoringkaraoke.EvalActivity.onCreate(EvalActivity.java:51)
W/System.err:     at android.app.Activity.performCreate(Activity.java:5447)
W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
W/System.err:     at android.app.ActivityThread.access$800(ActivityThread.java:166)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err:     at android.os.Looper.loop(Looper.java:136)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5590)
W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096)
W/System.err:     at dalvik.system.NativeStart.main(Native Method)
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@420c0bc8 time:3328964
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@42040820 time:3328965
void createExternalStoragePrivateFile() {
    // Create a path where we will place our private file on external
    // storage.
    File file = new File(getExternalFilesDir(null), "audio.3gp");

    try {
        // Very simple code to copy a picture from the application's
        // resource into the external file.  Note that this code does
        // no error checking, and assumes the picture is small (does not
        // try to copy it in chunks).  Note that if external storage is
        // not currently mounted this will silently fail.
        InputStream is = getResources().openRawResource(R.drawable.abaa);
        OutputStream os = new FileOutputStream(file);
        byte[] data = new byte[is.available()];
        is.read(data);
        os.write(data);
        is.close();
        os.close();
    } catch (IOException e) {
        // Unable to create file, likely because external storage is
        // not currently mounted.
        Log.w("ExternalStorage", "Error writing " + file, e);
    }
}

void deleteExternalStoragePrivateFile() {
    // Get path for the file on external storage.  If external
    // storage is not currently mounted this will fail.
    File file = new File(getExternalFilesDir(null), "audio.3gp");
    if (file != null) {
        file.delete();
    }
}

boolean hasExternalStoragePrivateFile() {
    // Get path for the file on external storage.  If external
    // storage is not currently mounted this will fail.
    File file = new File(getExternalFilesDir(null), "audio.3gp");
    if (file != null) {
        return file.exists();
    }
    return false;
}