Here you can find the source of deleteDirectory(String dir_path)
Parameter | Description |
---|---|
dir_path | - the directory path |
static public boolean deleteDirectory(String dir_path)
//package com.java2s; /* Copyright (C) 2003-2016 Patrick G. Durand * * 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.//from w w w. ja v a 2 s. c om */ import java.io.File; public class Main { /** * Utilitary method to delete the directory corresponding to the given path * * @param dir_path * - the directory path * @return boolean - true if directory was succesfully deleted */ static public boolean deleteDirectory(String dir_path) { return deleteDirectory(new File(dir_path)); } /** * Utilitary method to delete the directory given as parameter * * @param dir * - the directory to delete * @return boolean - true if directory was succesfully deleted */ public static boolean deleteDirectory(File dir) { if (dir.exists()) { File[] files = dir.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { deleteDirectory(files[i]); } else { files[i].delete(); } } } return (dir.delete()); } }