Here you can find the source of deleteFolderRecursive(File folder)
public static int deleteFolderRecursive(File folder)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Liviu Ionescu.//from w w w . j ava 2 s . c o m * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Liviu Ionescu - initial version *******************************************************************************/ import java.io.File; public class Main { public static int deleteFolderRecursive(File folder) { int count = 0; if (folder == null) return count; if (folder.exists()) { for (File f : folder.listFiles()) { if (f.isDirectory()) { count += deleteFolderRecursive(f); f.setWritable(true, false); f.delete(); } else { f.setWritable(true, false); f.delete(); count++; } } folder.setWritable(true, false); folder.delete(); } return count; } }