Here you can find the source of deleteDirWithContent(final String path)
public static boolean deleteDirWithContent(final String path)
//package com.java2s; /*// ww w . j a va2 s . c om * Copyright 2016 IKS Gesellschaft fuer Informations- und Kommunikationssysteme mbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; public class Main { public static boolean deleteDirWithContent(final String path) { final File dir = new File(path); return deleteDirWithContent(dir); } public static boolean deleteDirWithContent(final File dir) { boolean ok = true; if (dir.exists() && dir.isDirectory()) { final File[] listFiles = dir.listFiles(); for (int i = 0; i < listFiles.length; i++) { if (listFiles[i].isDirectory()) { deleteDirWithContent(listFiles[i]); } else { boolean b = listFiles[i].delete(); if (ok) ok = b; } } boolean b = dir.delete(); if (ok) ok = b; } return ok; } }