--- old/src/java.base/share/classes/java/io/File.java 2019-07-10 13:58:16.469544127 +0200 +++ new/src/java.base/share/classes/java/io/File.java 2019-07-10 13:58:16.373544609 +0200 @@ -1062,8 +1062,9 @@ * Deletion will be attempted only for normal termination of the * virtual machine, as defined by the Java Language Specification. * - *

Once deletion has been requested, it is not possible to cancel the - * request. This method should therefore be used with care. + *

+ * Once deletion has been requested, it may be cancelled by invoking + * {@link #cancelDeleteOnExit()}. * *

* Note: this method should not be used for file-locking, as @@ -1076,6 +1077,7 @@ * java.lang.SecurityManager#checkDelete} method denies * delete access to the file * + * @see #cancelDeleteOnExit * @see #delete * * @since 1.2 @@ -1092,6 +1094,26 @@ } /** + * Cancels any request that the file or directory denoted by this + * abstract pathname be deleted when the virtual machine terminates. + * Invoking this method for a file or directory that is not already + * registered for deletion has no effect. If a file or directory is + * registered for deletion but is explicitly deleted before normal + * termination of the virtual machine, then it is recommended to call + * this method to free resources used to track the file for deletion. + * + * @see #deleteOnExit + * + * @since 14 + */ + public void cancelDeleteOnExit() { + if (isInvalid()) { + return; + } + DeleteOnExitHook.remove(path); + } + + /** * Returns an array of strings naming the files and directories in the * directory denoted by this abstract pathname. *