Here you can find the source of forceDelete(final File file)
Parameter | Description |
---|---|
file | file or directory to delete, must not be null |
Parameter | Description |
---|---|
IOException | in case deletion is unsuccessful |
public static void forceDelete(final File file) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; public class Main { /**// ww w. ja v a2s .c o m * Deletes a file. If file is a directory, delete it and all sub-directories. * * @param file file or directory to delete, must not be null * @throws IOException in case deletion is unsuccessful */ public static void forceDelete(final File file) throws IOException { if (file.exists()) { if (file.isDirectory()) { for (final File c : file.listFiles()) { forceDelete(c); } } if (!file.delete()) { throw new IOException("Failed to delete " + file.getAbsolutePath()); } } } }