Java Files.delete(Path path)
Syntax
Files.delete(Path path) has the following syntax.
public static void delete(Path path) throws IOException
Example
In the following code shows how to use Files.delete(Path path) method.
// w w w . j av a 2s. c o m
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Files;
import java.nio.file.FileSystems;
public class Main {
public static void main(String[] args) {
Path path = FileSystems.getDefault().getPath("C:/tutorial/photos", "Demo.jpg");
//delete the file
try {
Files.delete(path);
} catch (IOException | SecurityException e) {
System.err.println(e);
}
}
}
The code above generates the following result.