Android 写PCM 到SDCARD

权限

 

Code

init

    static final String RECORD_FILE_NAME = "record.pcm";
    private static File recordFile = null;
    private static FileOutputStream fos = null;

    private void initFileStream(){
        recordFile = new File(Environment.getExternalStorageDirectory() +"/" + RECORD_FILE_NAME);
        if (!recordFile.mkdirs()) {
            Log.e(TAG, "Directory not created");
        }
        if (recordFile.exists()) {
            recordFile.delete();
        }

        try {
            fos = new FileOutputStream(recordFile);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

write

        if (fos != null) {
            try {
                fos.write(bytes);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

Close

 private void closeFileStream(){
        try {
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

你可能感兴趣的:(Android 写PCM 到SDCARD)