Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.os.Environment; import java.io.File; public class Main { public static void cleanExternalCache(Context context) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { deleteFilesByDirectory(context.getExternalCacheDir()); } } private static void deleteFilesByDirectory(File directory) { if (directory != null && directory.exists() && directory.isDirectory()) { for (File item : directory.listFiles()) { if (item.isDirectory()) { deleteFilesByDirectory(item); } item.delete(); } directory.delete(); } } }