Here you can find the source of deleteDir(File dir)
Parameter | Description |
---|---|
dir | the directory to delete |
public static boolean deleteDir(File dir)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**//from w w w . j a v a 2 s .c om * Deletes all files and subdirectories under dir and dir itself. Returns * true if all deletions were successful. If a deletion fails, the method * stops attempting to delete and returns false. * * @param dir the directory to delete * @return rue if all deletions were successful */ public static boolean deleteDir(File dir) { boolean empty = emptyDir(dir); if (!empty) { return false; } return dir.delete(); } /** * Deletes all files and subdirectories under dir. Returns true if all * deletions were successful. If a deletion fails, the method stops * attempting to delete and returns false. * * @param dir the directory to delete * * @return rue if all deletions were successful */ public static boolean emptyDir(File dir) { if (dir.isDirectory()) { for (File child : dir.listFiles()) { boolean success = deleteDir(child); if (!success) { return false; } } } return true; } }