Java Delete Tree delTree(File file)

Here you can find the source of delTree(File file)

Description

Recursively deletes all contents of the given directory.

License

BSD License

Parameter

Parameter Description
file the directory to delete

Declaration

public static void delTree(File file) 

Method Source Code


//package com.java2s;
/*//from   ww w  .j  av  a  2  s.  c o m
 * Copyright (c) 2008-2011 by Bjoern Kolbeck, Jan Stender,
 *               Felix Langner, Zuse Institute Berlin
 *
 * Licensed under the BSD License, see LICENSE file for details.
 *
 */

import java.io.File;

public class Main {
    /**
     * Recursively deletes all contents of the given directory.
     *
     * @param file
     *            the directory to delete
     */
    public static void delTree(File file) {

        if (!file.exists())
            return;

        File[] fileList;
        if ((fileList = file.listFiles()) != null) {
            for (File f : fileList) {
                if (f.isDirectory())
                    delTree(f);
                else
                    f.delete();
            }
        }

        file.delete();
    }
}

Related

  1. delTree(File f)
  2. delTree(File file)
  3. delTree(File file)
  4. delTree(File file)
  5. delTree(File file)
  6. delTree(File file)
  7. deltree(File root)
  8. delTree(File root)
  9. deltree(final String directory)