download file to sd card

need to write a method
 
  
public void saveFile(Bitmap bm, String fileName) throws IOException { File dirFile = new File(Environment. getExternalStorageDirectory ().getPath()); if (!dirFile.exists()) { dirFile.mkdir(); } fileName = UUID. randomUUID ().toString() + ".jpg" ; File jia = new File(Environment. getExternalStorageDirectory ().getPath() + "/imgpic/" ); if (!jia.exists()) { //判断文件夹是否存在,不存在则创建 jia.mkdirs(); } File myCaptureFile = new File(jia + "/" + fileName); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(myCaptureFile)); bm.compress(Bitmap.CompressFormat. JPEG , 80 , bos); bos.flush(); bos.close(); }
Then put it in the resources you need to put,


 
  
saveFile( bitmap , Environment. getExternalStorageDirectory () + "/imgpic/" );
This bitmap can be an image or a file

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324824270&siteId=291194637