权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
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();
}
}