![]() |
VOOZH | about |
The delete() method of java.nio.file.Files help us to delete a file located at the path passed as a parameter. This method may not be atomic with respect to other file system operations. If the file is a symbolic link then the symbolic link itself, not the final target of the link, is deleted. If the file is a directory then this method will delete that file only when the directory is empty. In some implementations, a directory has entries for special files or links that are created when the directory is created. In such implementations, a directory is considered empty when only the special entries exist. In such cases, Directories can be deleted using this method. On some operating systems it may not be possible to remove a file when it is open and in use by this Java virtual machine or other programs.
Syntax:
public static void delete(Path path) throws IOException
Parameters: This method accepts a parameter path which is the path to the file to delete.
Return value: This method returns nothing.
Exception: This method will throw following exceptions:
Below programs illustrate delete(Path) method:
Program 1:
Program 2:
References: https://docs.oracle.com/javase/10/docs/api/java/nio/file/Files.html#delete(java.nio.file.Path)