public static void dumbDeleteRecursive ( File file ) throws IOException { if ( file . isDirectory ( ) ) { File [ ] fileList = file . listFiles ( ) ; if ( fileList == null ) { // If file is not a directory, listFiles() will return null return ; } for ( File entry : fileList ) { dumbDeleteRecursive ( entry ) ; } } if ( ! file . delete ( ) && file . exists ( ) ) { throw new IOException ( "could not delete: " + file ) ; } }
Delete a directory and its contents .