public static File createTempDir(File dir,boolean cleanup) throws IOException {
  if (!dir.mkdirs() && !dir.exists()) {
    throw new IOException(String.format("Failed to create directory structure '%s'",dir.toString()));
  }
  if (cleanup) {
    addCleanupHook(dir.toPath());
  }
  return dir;
}

public static File createTempDir ( File dir , boolean cleanup ) throws IOException { if ( ! dir . mkdirs ( ) && ! dir . exists ( ) ) { throw new IOException ( String . format ( "Failed to create directory structure '%s'" , dir . toString ( ) ) ) ; } if ( cleanup ) { addCleanupHook ( dir . toPath ( ) ) ; } return dir ; }
create directory that is automatically cleaned up after the jvm shuts down through use of a runtime shutdown hook .
