public void clearDirectory(File directory){
  if (directory.exists()) {
    for (    File file : directory.listFiles()) {
      file.delete();
    }
  }
}

public void clearDirectory ( File directory ) { if ( directory . exists ( ) ) { for ( File file : directory . listFiles ( ) ) { file . delete ( ) ; } } }
warning : deletes the content of a directory . this is an i / o operation and this method executes in the main thread , so it is recommended to perform the operation using another thread .
