Here you can find the source of deleteDirectory(File path)
static public boolean deleteDirectory(File path)
//package com.java2s; /****************************************************************************** * Copyright (c) 2005-2008 Whirlwind Match Limited. All rights reserved. * * This is open source software; you can use, redistribute and/or modify * it under the terms of the Open Software Licence v 3.0 as published by the * Open Source Initiative.//from w w w .j av a2 s. c o m * * You should have received a copy of the Open Software Licence along with this * application. if not, contact the Open Source Initiative (www.opensource.org) *****************************************************************************/ import java.io.File; import java.util.logging.Logger; public class Main { static private Logger log; static public boolean deleteDirectory(File path) { boolean deleted = deleteDirectoryInternal(path); log.info(deleted ? "Delete succeeded for path: " + path : "Delete failed for path: " + path); return deleted; } static private boolean deleteDirectoryInternal(File path) { if (!path.exists()) { return true; } File[] files = path.listFiles(); boolean succeeded = true; for (File file : files) { if (file.isDirectory()) { succeeded &= deleteDirectoryInternal(file); } else { succeeded &= file.delete(); } } return succeeded && path.delete(); // Deliberately won't call path.delete() if !succeeded (it'll fail) } }