Here you can find the source of deleteFile(Path path)
Parameter | Description |
---|---|
path | the path to the file to delete. |
Parameter | Description |
---|---|
IOException | if something goes wrong. |
public static void deleteFile(Path path) throws IOException
//package com.java2s; import java.io.IOException; import java.nio.file.*; public class Main { /**/*from ww w. j a va2s . c o m*/ * Deletes a file if it exists. * * @param path the path to the file to delete. * @throws IOException if something goes wrong. */ public static void deleteFile(Path path) throws IOException { if (!isFolder(path)) { Files.deleteIfExists(path); } } /** * Tests whether a file is a directory. * * @param path the path to the file to test. * @return true if the file is a directory; false if the file does not * exist, is not a directory, or it cannot be determined if the file * is a directory or not. */ public static boolean isFolder(Path path) { return Files.isDirectory(path); } }