Java Utililty Methods Delete File on Exit

List of utility methods to do Delete File on Exit

Description

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

Method

voiddeleteOnExit(File dir)
delete On Exit
synchronized (temporary) {
    if (temporary.isEmpty()) {
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            public void run() {
                synchronized (temporary) {
                    for (File dir : temporary) {
                        deleteFileOrDir(dir, 256);
        }, "Temporary Directory Cleanup"));
    temporary.add(dir);
voiddeleteOnExit(File file)
Delete physically the file but when the JVM exits (useful for temporary file)
if (!file.exists()) {
    return;
file.deleteOnExit();
voiddeleteOnExit(File file)
delete On Exit
delete.add(file.getAbsolutePath());
voiddeleteOnExit(final File file)
Requests in privileged mode that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates.
file.deleteOnExit();
voiddeleteOnExit(final File file)
Schedule a file to be deleted when JVM exits.
file.deleteOnExit();
if (file.isDirectory()) {
    File[] files = file.listFiles();
    if (files != null) {
        for (File child : files) {
            deleteOnExit(child);
voiddeleteOnExitRecursive(File file)
delete On Exit Recursive
if (!file.exists())
    return;
file.deleteOnExit();
if (!file.isDirectory())
    return;
for (File f : file.listFiles())
    deleteOnExitRecursive(f);