Java tutorial
//package com.java2s; import android.content.Context; import java.io.File; public class Main { private static File getOutputMediaFile(Context context, String thumbName) { File file = new File(context.getCacheDir() + "/thumbnails/" + thumbName + ".png"); if (!file.exists()) { File mediaStorageDir = new File(context.getCacheDir() + "/thumbnails"); // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { return null; } } // Create a media file name String mImageName = thumbName + ".png"; File mediaFile = new File(mediaStorageDir.getPath() + File.separator + mImageName); return mediaFile; } else { return file; } } }