21 lines
469 B
Java
21 lines
469 B
Java
package org.FileExamples.DeletingFiles;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
|
|
public class DeleteFileExample02 {
|
|
static void main() {
|
|
try
|
|
{
|
|
Path path = Path.of("example.txt");
|
|
Files.deleteIfExists(path);
|
|
System.out.println("File deleted if it existed.");
|
|
}
|
|
catch (IOException e)
|
|
{
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
}
|