Java tutorial
//package com.java2s; //License from project: Apache License import android.text.TextUtils; import java.io.File; public class Main { public static boolean deleteFile(String path) { // If path == null will throw NullPointException. if (TextUtils.isEmpty(path)) { return false; } File file = new File(path); if (!file.exists()) { return false; } boolean flag = file.delete(); File parent = file.getParentFile(); if (isEmptyDirectory(parent)) { parent.delete(); } return flag; } public static boolean isEmptyDirectory(File directory) { String[] names = directory.list(); return names == null || names.length == 0; } }