Java Utililty Methods Directory Delete on Exit

List of utility methods to do Directory Delete on Exit

Description

The list of methods to do Directory Delete on Exit are organized into topic(s).

Method

voidcleanDirectoryOnExit(File directory)
clean Directory On Exit
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);
IOException exception = null;
File[] files = directory.listFiles();
for (int i = 0; i < files.length; i++) {
    File file = files[i];
    try {
        forceDeleteOnExit(file);
    } catch (IOException ioe) {
        exception = ioe;
if (null != exception) {
    throw exception;
voidcleanDirectoryOnExit(File directory)
Cleans a directory without deleting net.
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;