Here you can find the source of deleteDirectory(final String fullDirPath)
static public boolean deleteDirectory(final String fullDirPath)
//package com.java2s; /****************************************************************************** * * CoreWall / Corelyzer - An Initial Core Description Tool * Copyright (C) 2004 - 2007 Arun Gangadhar Gudur Rao, Julian Yu-Chung Chen * Electronic Visualization Laboratory, University of Illinois at Chicago * * This software is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either Version 2.1 of the License, or * (at your option) any later version./* www . j a v a 2 s . c o m*/ * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser Public License along * with this software; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Questions or comments about CoreWall should be directed to * cavern@evl.uic.edu * *****************************************************************************/ import java.io.File; public class Main { static public boolean deleteDirectory(final String fullDirPath) { String sp = System.getProperty("file.separator"); File texDir = new File(fullDirPath); if (texDir.exists() && texDir.isDirectory()) { String[] dirList = texDir.list(); for (String aDirList : dirList) { String myDirPath = texDir.getAbsolutePath() + sp + aDirList; File d = new File(myDirPath); if (d.exists() && d.isDirectory()) { System.out.print("Delete " + d.getAbsolutePath()); boolean isSuccess = deleteDir(d); String result = isSuccess ? "SUCCESS" : "FAILED"; System.out.print(" : " + result + "\n"); } } texDir.delete(); } return false; } static public boolean deleteDir(final File dir) { if (dir.isDirectory()) { String[] children = dir.list(); for (String aChildren : children) { boolean success = deleteDir(new File(dir, aChildren)); if (!success) { return false; } } } // The directory is now empty so delete it return dir.delete(); } }