Java tutorial
//package com.java2s; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.graphics.Bitmap; public class Main { public static void save2Cache(Context context, String cover, Bitmap bitmap) { File file = new File(context.getCacheDir(), cover + ".png"); FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(file); if (bitmap != null) { if (bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream)) { fileOutputStream.flush(); } } } catch (FileNotFoundException e) { file.delete(); e.printStackTrace(); } catch (IOException e) { file.delete(); e.printStackTrace(); } finally { try { fileOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } }