Here you can find the source of deleteRecursively(File dirEntry)
Parameter | Description |
---|---|
dirEntry | A file or directory to be deleted. |
Parameter | Description |
---|---|
IOException | Thrown if deletion fails. |
public static void deleteRecursively(File dirEntry) throws IOException
//package com.java2s; //License from project: Apache License import static com.google.common.base.Preconditions.checkNotNull; import java.io.File; import java.io.IOException; public class Main { /**/*from w ww .java2 s . co m*/ * Deletes a file or directory (recursively). * * @param dirEntry * A file or directory to be deleted. * @throws IOException * Thrown if deletion fails. */ public static void deleteRecursively(File dirEntry) throws IOException { checkNotNull(dirEntry, "null directory entry"); if (!dirEntry.exists()) { return; } if (dirEntry.isDirectory()) { File[] files = dirEntry.listFiles(); if (files != null) { for (File file : files) { deleteRecursively(file); } } } if (!dirEntry.delete()) { throw new IOException("Failed to delete file: " + dirEntry.getAbsolutePath()); } } }