private static void cleanDirectoryOnExit(File directory) throws IOException {
  if (!directory.exists()) {
    String message=directory + " does not exist";
    throw new IllegalArgumentException(message);
  }
  if (!directory.isDirectory()) {
    String message=directory + " is not a directory";
    throw new IllegalArgumentException(message);
  }
  File[] files=directory.listFiles();
  if (files == null) {
    throw new IOException("Failed to list contents of " + directory);
  }
  IOException exception=null;
  for (  File file : files) {
    try {
      forceDeleteOnExit(file);
    }
 catch (    IOException ioe) {
      exception=ioe;
    }
  }
  if (null != exception) {
    throw exception;
  }
}

private static void cleanDirectoryOnExit ( File directory ) throws IOException { if ( ! directory . exists ( ) ) { String message = directory + " does not exist" ; throw new IllegalArgumentException ( message ) ; } if ( ! directory . isDirectory ( ) ) { String message = directory + " is not a directory" ; throw new IllegalArgumentException ( message ) ; } File [ ] files = directory . listFiles ( ) ; if ( files == null ) { throw new IOException ( "Failed to list contents of " + directory ) ; } IOException exception = null ; for ( File file : files ) { try { forceDeleteOnExit ( file ) ; } catch ( IOException ioe ) { exception = ioe ; } } if ( null != exception ) { throw exception ; } }
cleans a directory without deleting it .
