Here you can find the source of deleteDirectory(File path)
Parameter | Description |
---|---|
path | 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 { /**// w w w . ja va 2s . c o m * Convenience function to delete a directory. * * @param path Path to delete * @throws IOException If the operation fails. */ public static void deleteDirectory(File path) throws IOException { if (!path.exists()) return; for (File file : path.listFiles()) { 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)); } }