public static boolean delete ( File file ) { boolean result = true ; if ( file == null ) { return false ; } if ( file . exists ( ) ) { if ( file . isDirectory ( ) ) { // 1. delete content of directory: File [ ] children = file . listFiles ( ) ; for ( File child : children ) { //for each file: result = result && delete ( child ) ; } //next file } result = result && file . delete ( ) ; } //else: input directory does not exist or is not a directory return result ; }
Delete a File .