public static void deleteDirOnExit ( final File dir ) { if ( dir . isDirectory ( ) ) { final String [ ] children = dir . list ( ) ; for ( int i = 0 ; i < children . length ; i ++ ) { deleteDirOnExit ( new File ( dir , children [ i ] ) ) ; } } // The directory is now empty so delete it dir . deleteOnExit ( ) ; }
Delete a directory recursively . This method will delete all files and subdirectories .