Here you can find the source of emptyDir(File dir)
Parameter | Description |
---|---|
dir | the directory to delete |
public static boolean emptyDir(File dir)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**/*from w ww . j a v a 2s . co m*/ * 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; } /** * 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(); } }