Here you can find the source of deleteFile(File f)
Parameter | Description |
---|---|
f | - The file to delete. |
Parameter | Description |
---|---|
IOException | - If anything during the operation fails. |
public static void deleteFile(File f) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.nio.file.Files; public class Main { /**/*from w ww . j a v a2 s.c o m*/ * Helper function used to delete a file. Directories are only deleted if empty. * * @param f - The file to delete. * @throws IOException - If anything during the operation fails. */ public static void deleteFile(File f) throws IOException { deleteFile(f, false); } /** * Helper function used to delete a file. * If a directory and we want it, recursively delete all sub files and directories. * * @param f - The file to delete. * @param recursive - Whether to delete recursively files in folders. If not, only empty folder will be deleted. * @throws IOException - If anything during the operation fails. */ public static void deleteFile(File f, boolean recursive) throws IOException { if (recursive && f.isDirectory()) { for (File c : f.listFiles()) { deleteFile(c, recursive); } } Files.deleteIfExists(f.toPath()); } }