Java Delete Directory deleteDirectory(File directory)

Here you can find the source of deleteDirectory(File directory)

Description

delete Directory

License

Open Source License

Declaration

public static void deleteDirectory(File directory) 

Method Source Code

//package com.java2s;
/* MOD_V2.0/*from  www.j a va2s .c  o m*/
 * Copyright (c) 2012 OpenDA Association
 * All rights reserved.
 * 
 * This file is part of OpenDA. 
 * 
 * OpenDA is free software: you can redistribute it and/or modify 
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 3 of 
 * the License, or (at your option) any later version. 
 * 
 * OpenDA is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * GNU Lesser General Public License for more details. 
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with OpenDA.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.*;

public class Main {
    public static void deleteDirectory(File directory) {

        if (directory.getPath().length() <= 4) {
            throw new IllegalArgumentException("Path length is too short");
        }

        for (File file : directory.listFiles()) {
            if (file.isDirectory()) {
                deleteDirectory(file);
            } else {
                boolean success = file.delete();
                //                if (!success) {
                //                    throw new RuntimeException("Could not delete file " + file.getAbsolutePath());
                //                }
            }
        }
        boolean success = directory.delete();
        //        if (!success) {
        //            throw new RuntimeException("Could not delete directory " + directory.getAbsolutePath());
        //        }
    }
}

Related

  1. deleteDirectory(File directory)
  2. deleteDirectory(File directory)
  3. deleteDirectory(File directory)
  4. deleteDirectory(File directory)
  5. deleteDirectory(File directory)
  6. deleteDirectory(File directory)
  7. deleteDirectory(File directory)
  8. deleteDirectory(File directory)
  9. deleteDirectory(File directory)