Here you can find the source of deleteDirectory(File path)
Delete a non-empty directory Copied from http://www.rgagnon.com/javadetails/java-0483.html
Parameter | Description |
---|---|
path | a parameter |
public static boolean deleteDirectory(File path)
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { /**/* w w w . j a v a 2 s . c o m*/ * Delete a non-empty directory * Copied from http://www.rgagnon.com/javadetails/java-0483.html * @param path * @return true if and only if the file or directory is successfully deleted; false otherwise */ public static boolean deleteDirectory(File path) { boolean succeeded = true; // first empty it if (path.exists()) { File[] files = path.listFiles(); if (files != null) { for (int i = 0; succeeded && (i < files.length); i++) { if (files[i].isDirectory()) { succeeded &= deleteDirectory(files[i]); } else { succeeded &= files[i].delete(); } } } } // then delete it if (succeeded) succeeded &= path.delete(); return succeeded; } }