Here you can find the source of deleteDirectoryInternal(File path)
static private boolean deleteDirectoryInternal(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.//w ww . j a v a 2s . co 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; public class Main { 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) } }