Java Path Delete nio deleteOnExit(Path path)

Here you can find the source of deleteOnExit(Path path)

Description

Register Path for a delete on JM shutdown event.

License

Open Source License

Parameter

Parameter Description
path path to delete

Declaration

public static void deleteOnExit(Path path) 

Method Source Code

//package com.java2s;
/*// w  ww  . j a v a 2  s.c om
 *    Geotoolkit.org - An Open Source Java GIS Toolkit
 *    http://www.geotoolkit.org
 *
 *    (C) 2008-2012, Open Source Geospatial Foundation (OSGeo)
 *    (C) 2009-2012, Geomatys
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

import java.nio.file.*;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class Main {
    /**
     * Keep all {@link Path} to delete on JVM shutdown event on a concurrent Set.
     */
    private static final Set<Path> DELETE_ON_EXIT_PATHS = Collections
            .newSetFromMap(new ConcurrentHashMap<Path, Boolean>());

    /**
     * Register {@link Path} for a delete on JM shutdown event.
     * Under the hood, this method register path to be delete using {@link Runtime#addShutdownHook(Thread)}.
     *
     * @param path path to delete
     */
    public static void deleteOnExit(Path path) {
        DELETE_ON_EXIT_PATHS.add(path);
    }
}

Related

  1. deleteIfExists(Path thePath)
  2. deleteIfExists(Path value)
  3. deleteIndexBeforeStart(String basePath)
  4. deleteLockFile(Path logFile)
  5. deleteNotEmptyDirectory(Path path)
  6. deletePath(Path path)
  7. deletePathRecursively(String path)
  8. deleteQuietly(@Nullable Path path)
  9. deleteQuietly(Path dir)