Java tutorial
//package com.java2s; import java.io.File; import java.io.IOException; import android.content.Context; import android.util.Log; public class Main { public static final String TAG = "Utils"; public static final String CACHE_DIR_NAME = "__vimeo_v_cache"; private static File cacheDir = null; private static boolean cacheDirCreated = false; public static File newTempFile(Context context, String prefix, String suffix) throws IOException { return File.createTempFile(prefix, suffix, getDefaultCacheDir(context)); } public static File getDefaultCacheDir(Context context) { if (cacheDirCreated) return cacheDir; else { cacheDir = createCacheDir(context, CACHE_DIR_NAME); cacheDirCreated = true; return cacheDir; } } public static File createCacheDir(Context context, String dirName) { File preparedDir; if (android.os.Environment.MEDIA_MOUNTED.equals(android.os.Environment.getExternalStorageState())) { preparedDir = context.getDir(dirName /* + UUID.randomUUID().toString()*/, Context.MODE_PRIVATE); Log.i(TAG, "Cache dir initialized at SD card " + preparedDir.getAbsolutePath()); } else { preparedDir = context.getCacheDir(); Log.i(TAG, "Cache dir initialized at phone storage " + preparedDir.getAbsolutePath()); } if (!preparedDir.exists()) { Log.i(TAG, "Cache dir not existed, creating"); preparedDir.mkdirs(); } return preparedDir; } }