Here you can find the source of deleteDirectory(File path)
Parameter | Description |
---|---|
path | the path to delete |
Parameter | Description |
---|---|
IOException | If the operation fails. |
public static void deleteDirectory(File path) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; public class Main { /**//from w w w . jav a 2s .c o m * Convenience function to delete a directory. * * @param path the path to delete * @throws IOException If the operation fails. */ public static void deleteDirectory(File path) throws IOException { if (!path.exists()) return; final File[] files = path.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) deleteDirectory(file); else if (!file.delete()) { throw new IOException(String.format("Unable to delete file '%s'", file)); } } } if (!path.delete()) throw new IOException(String.format("Unable to delete directory '%s'", path)); } }