Java tutorial
//package com.java2s; import android.content.Context; import android.os.Environment; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static final String POSTFIX = ".JPEG"; public static final String APP_NAME = "ImageSelector"; public static final String CROP_PATH = "/" + APP_NAME + "/CropImage/"; public static File createCropFile(Context context) { return createMediaFile(context, CROP_PATH); } private static File createMediaFile(Context context, String parentPath) { String state = Environment.getExternalStorageState(); File rootDir = state.equals(Environment.MEDIA_MOUNTED) ? Environment.getExternalStorageDirectory() : context.getCacheDir(); File folderDir = new File(rootDir.getAbsolutePath() + parentPath); if (!folderDir.exists() && folderDir.mkdirs()) { } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date()); String fileName = APP_NAME + "_" + timeStamp + ""; File tmpFile = new File(folderDir, fileName + POSTFIX); return tmpFile; } }