private void storeFile(InputStream mInputStream) throws IOException {
try {
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File(sdCard.getAbsolutePath() + "/abc1");
dir.mkdirs();
File file = new File(dir, "cacheFileAppeal.wav");
OutputStream output = new FileOutputStream(file);
try {
try {
byte[] buffer = new byte[4 * 1024]; // or other buffer size
int read;
while ((read = mInputStream.read(buffer)) != -1) {
output.write(buffer, 0, read);
}
output.flush();
} finally {
output.close();
}
} catch (Exception e) {
e.printStackTrace(); // handle exception, define IOException and others
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
mInputStream.close();
}
} |