public static void deleteDirectory ( File directory ) throws IOException { requireNonNull ( directory , DIRECTORY_CAN_NOT_BE_NULL ) ; if ( ! directory . exists ( ) ) { return ; } Path path = directory . toPath ( ) ; if ( Files . isSymbolicLink ( path ) ) { throw new IOException ( format ( "Directory '%s' is a symbolic link" , directory ) ) ; } if ( directory . isFile ( ) ) { throw new IOException ( format ( "Directory '%s' is a file" , directory ) ) ; } deleteDirectoryImpl ( path ) ; if ( directory . exists ( ) ) { throw new IOException ( format ( "Unable to delete directory '%s'" , directory ) ) ; } }
Deletes a directory recursively . Does not support symbolic link to directories .