public static void deleteFile(final File file,final boolean deleteDir){
  if (file.isDirectory()) {
    for (    final File subFile : file.listFiles()) {
      deleteFile(subFile,true);
    }
    if (deleteDir) {
      file.delete();
    }
  }
 else {
    file.delete();
  }
}

public static void deleteFile ( final File file , final boolean deleteDir ) { if ( file . isDirectory ( ) ) { for ( final File subFile : file . listFiles ( ) ) { deleteFile ( subFile , true ) ; } if ( deleteDir ) { file . delete ( ) ; } } else { file . delete ( ) ; } }
deletes the file , or all files in the directory . optionally the directory itself too .
