Java Delete Directory deleteDirectory(File dir, boolean recursive)

Here you can find the source of deleteDirectory(File dir, boolean recursive)

Description

deletes all files in a director

License

Open Source License

Parameter

Parameter Description
recursive a parameter

Declaration

public static void deleteDirectory(File dir, boolean recursive) throws IOException 

Method Source Code


//package com.java2s;
/*/*from   w  ww  .ja  va  2s . co  m*/
 * This file is part of the Jose Project
 * see http://jose-chess.sourceforge.net/
 * (c) 2002-2006 Peter Sch?fer
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 */

import java.io.*;

public class Main {
    /**
     * deletes all files in a director
     * @param recursive 
     */
    public static void deleteDirectory(File dir, boolean recursive) throws IOException {
        if (!dir.isDirectory())
            throw new IllegalArgumentException("directory expected");

        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory() && recursive)
                deleteDirectory(files[i], true);
            files[i].delete();
        }
    }
}

Related

  1. deleteDirectory(File dir)
  2. deleteDirectory(File dir)
  3. deleteDirectory(File dir)
  4. deleteDirectory(File dir, boolean isInitialDelete)
  5. deleteDirectory(File dir, boolean isInitialDelete)
  6. deleteDirectory(File dir, Map preserve)
  7. deleteDirectory(File directory)
  8. deleteDirectory(File directory)
  9. deleteDirectory(File directory)