public static boolean deleteFile ( File file ) throws IOException { if ( ! file . exists ( ) ) return false ; File [ ] files = file . listFiles ( ) ; if ( files != null ) { for ( int i = 0 ; i < files . length ; i ++ ) { File childFile = files [ i ] ; if ( childFile . equals ( file ) ) continue ; if ( childFile . isDirectory ( ) ) deleteFile ( childFile ) ; else childFile . delete ( ) ; } } return file . delete ( ) ; }
Deletes the file provided . If it is a directory recursively deletes a directory and its content .