public static void deleteContents(File dir) throws IOException {
  File[] files=dir.listFiles();
  if (files != null) {
    for (    File file : files) {
      if (file.isDirectory()) {
        deleteContents(file);
      }
      file.delete();
    }
  }
}

public static void deleteContents ( File dir ) throws IOException { File [ ] files = dir . listFiles ( ) ; if ( files != null ) { for ( File file : files ) { if ( file . isDirectory ( ) ) { deleteContents ( file ) ; } file . delete ( ) ; } } }
do not use . use createtemporarydirectory instead . used by frameworks / base unit tests to clean up a temporary directory . deliberately ignores errors , on the assumption that test cleanup is only supposed to be best - effort .
