Here you can find the source of deleteRecursive(File toDelete)
Parameter | Description |
---|---|
folderToDelete | Folder to delete with all of its contents |
public static void deleteRecursive(File toDelete) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; public class Main { /**//from www. ja v a 2 s .c om * This method acts much like bash's "rm -rf $file" command. It will * delete the directory and all of its contents! If the File passed is * not a folder, it will be deleted, too. * * **This WILL follow symlinks! Be careful! * * @param folderToDelete Folder to delete with all of its contents * @return Whether the delete was successful */ public static void deleteRecursive(File toDelete) throws IOException { for (File sub : toDelete.listFiles()) { if (sub.isDirectory()) { deleteRecursive(sub); } else { if (!sub.delete()) { throw new IOException(); } } } } }