Unable to save mp3 file in some specific device [c

2019-09-23 02:24发布

问题:

In my project I put this code to copy mp3 file here writefile is the function that copies file.

code is correctly working on devices except Moto G with Android 5.1

p_name = mp_name.concat(".mp3");
        InputStream inputStream = null;

        try {
            inputStream = getResources().openRawResource(mpTrake[id]);
            byte[] reader = new byte[inputStream.available()];
            while (inputStream.read(reader) != -1) {
            }
            writefile(reader, "/sdcard/" + mp_name);
            Log.i("setring", "success");
        } catch (IOException e) {
            Log.i("setring", e.getMessage());
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    Log.i("setring", e.getMessage());
                }
            }
        }

回答1:

May be is file path problem If you have set path to \sdcard\ but phone has not inserted sd card then you get errors



标签: java android mp3