code: private static void cleanDirectory(final File directory) throws IOException {
          if ( !directory.exists() ) {
              return;
          }
  
          if ( !directory.isDirectory() ) {
              return;
          }
  
          IOException exception = null;
  
          final File[] files = directory.listFiles();
          if (files != null) {
              for (final File file : files) {
                  try {
                      cleanDirectory(file);
                      if (!file.delete()) {
                          throw new IOException("Cannot delete "+file.getAbsolutePath());
                      }
                  } catch (final IOException ioe) {
                      exception = ioe;
                  }
              }
          }
  
          if ( null != exception ) {
              throw exception;
          }
      }
docs: Clean a directory without deleting it.