Here you can find the source of deleteRecursively(File root)
Parameter | Description |
---|---|
root | the root <code>File</code> to delete |
true
if the File
was deleted, otherwise false
public static boolean deleteRecursively(File root)
//package com.java2s; /*/*from ww w .ja va 2 s .c o m*/ * Copyright 1999-2004 Alibaba.com All right reserved. This software is the * confidential and proprietary information of Alibaba.com ("Confidential * Information"). You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ import java.io.File; public class Main { /** * Delete the supplied {@link File} - for directories, * recursively delete any nested directories or files as well. * @param root the root <code>File</code> to delete * @return <code>true</code> if the <code>File</code> was deleted, * otherwise <code>false</code> */ public static boolean deleteRecursively(File root) { if (root != null && root.exists()) { if (root.isDirectory()) { File[] children = root.listFiles(); if (children != null) { for (int i = 0; i < children.length; i++) { deleteRecursively(children[i]); } } } return root.delete(); } return false; } }