Java File Path Delete deleteDir(File dir)

Here you can find the source of deleteDir(File dir)

Description

Deletes the specified directory and any files it and directories contains.

License

Open Source License

Parameter

Parameter Description
dir a parameter

Declaration

public static void deleteDir(File dir) 

Method Source Code

//package com.java2s;
/**//from  w w  w  . j  ava 2  s .  com
 * WSIT Build Tools (http://aikidojohn.github.com/wsitbt/)
 *
 * Copyright (c) 2011 Application Security, Inc.
 *
 * 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:
 *     Application Security, Inc.
 */

import java.io.File;

public class Main {
    /**
     * Deletes the specified directory and any files it and directories contains.
     * @param dir
     */
    public static void deleteDir(File dir) {
        for (String filename : dir.list()) {
            File file = new File(dir.getAbsolutePath() + "/" + filename);
            if (file.isDirectory()) {
                deleteDir(file);
            } else {
                file.delete();
            }
        }
        dir.delete();
    }
}

Related

  1. deleteDir(File dir)
  2. deleteDir(File dir)
  3. deleteDir(File dir)
  4. deleteDir(File dir)
  5. deleteDir(File dir)
  6. deleteDir(File dir)
  7. deleteDir(File dir)
  8. deleteDir(File dir)
  9. deleteDir(File dir)