Here you can find the source of deleteDir(File dir)
Parameter | Description |
---|---|
dir | The directory to delete. |
true
if and only if the directory is successfully deleted; false
otherwise
public static boolean deleteDir(File dir)
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { /**/*www. ja v a 2 s. co m*/ * Recursively delete a directory and all its contents. * * @param dir The directory to delete. * @return <code>true</code> if and only if the directory is successfully deleted; <code>false</code> otherwise */ public static boolean deleteDir(File dir) { if (!dir.isDirectory()) { throw new IllegalArgumentException(dir + " does not exist or is not a directory"); } File[] contents = dir.listFiles(); for (File file : contents) { if (file.isDirectory()) { deleteDir(file); } else { file.delete(); } } return dir.delete(); } }