Java Delete File on Exit deleteOnExit(final File file)

Here you can find the source of deleteOnExit(final File file)

Description

Schedule a file to be deleted when JVM exits.

License

Apache License

Declaration

public static void deleteOnExit(final File file) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    /**/*from  w  ww  .j av  a 2  s  . c o  m*/
     * Schedule a file to be deleted when JVM exits.
     * If file is directory delete it and all sub-directories.
     */
    public static void deleteOnExit(final File file) {
        file.deleteOnExit();
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            if (files != null) {
                for (File child : files) {
                    deleteOnExit(child);
                }
            }
        }
    }
}

Related

  1. deleteOnExit(File dir)
  2. deleteOnExit(File file)
  3. deleteOnExit(File file)
  4. deleteOnExit(final File file)
  5. deleteOnExitRecursive(File file)