AsynchttpClient下载文件,以文件流的形式


 /**
* 保存文件 以文件流的形式
*/

Bitmap bitmap = BitmapFactory.decodeByteArray(binaryData, 0, binaryData.length);
File directory = new File(Environment.getExternalStorageDirectory(), "asynchttp");
if (!directory.exists()) {
directory.mkdirs();//创建文件夹 MKDIRS S
}

File file = new File(directory, "picture" + System.currentTimeMillis() + ".jpg");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
// 压缩格式
Bitmap.CompressFormat format = Bitmap.CompressFormat.JPEG;
// 压缩比例
int quality = 100;

if (file.exists()) {
file.delete();
}
try {
file.createNewFile();
OutputStream stream = new FileOutputStream(file);
bitmap.compress(format, quality, stream);//压缩格式 压缩比例 输出流
stream.close();
Log.e(TAG, "onSuccess: "+"保存成功" );
} catch (IOException e) {
e.printStackTrace();
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM