Here you can find the source of deleteRecursively(File file)
public static void deleteRecursively(File file)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011, 2014 EclipseSource and others. * 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://from w w w . j a va 2 s. c om * EclipseSource - initial API and implementation ******************************************************************************/ import java.io.File; public class Main { public static void deleteRecursively(File file) { if (file.exists()) { File[] files = file.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { deleteRecursively(files[i]); } } boolean deleted = file.delete(); if (!deleted) { throw new RuntimeException("Could not delete file or directory: " + file.getAbsolutePath()); } } } }