Java Directory Clear clearDirectory(String path)

Here you can find the source of clearDirectory(String path)

Description

clear Directory

License

Apache License

Declaration

public static void clearDirectory(String path) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;

public class Main {
    public static void clearDirectory(String path) {
        deleteDirectory(path);//from w  ww  .j  a  v  a  2  s . c o  m
        File dir = new File(path);
        if (!dir.exists())
            dir.mkdir();
    }

    public static boolean deleteDirectory(String path) {
        return deleteDirectory(new File(path));
    }

    public static boolean deleteDirectory(File path) {
        if (path.exists()) {
            File[] files = path.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    deleteDirectory(files[i]);
                } else {
                    files[i].delete();
                }
            }
        }
        return (path.delete());
    }
}

Related

  1. clearDirectory(File f)
  2. clearDirectory(File f)
  3. clearDirectory(File src)
  4. clearDirectory(String absolutePath)
  5. clearDirectory(String dir)