Java tutorial
//package com.java2s; import android.text.TextUtils; import java.io.File; public class Main { public static boolean deleteFile(String path) { if (TextUtils.isEmpty(path)) { return true; } File file = new File(path); if (!file.exists()) { return true; } if (file.isFile()) { return file.delete(); } if (!file.isDirectory()) { return false; } File[] files = file.listFiles(); if (files == null || files.length == 0) { return file.delete(); } for (File f : files) { if (isFileExists(f)) { f.delete(); } else if (f.isDirectory()) { deleteFile(f.getAbsolutePath()); } } return file.delete(); } public static boolean isFileExists(File file) { return file != null && file.isFile() && file.exists(); } public static boolean isFileExists(String filePath) { if (!TextUtils.isEmpty(filePath)) { File file = new File(filePath); return isFileExists(file); } else { return false; } } }