Java Directory Clear cleanDirectory(File dir)

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

Description

clean Directory

License

Open Source License

Declaration

public static File cleanDirectory(File dir) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {

    public static File cleanDirectory(File dir) {
        if (dir.isFile()) {
            return null;
        }/*  w w  w .  j  a v a  2 s  .c o m*/
        delete(dir);
        dir.mkdirs();
        return dir;
    }

    public static boolean isFile(File file) {
        return file != null && file.isFile();
    }

    public static void delete(File root) {
        if (root.isFile()) {
            root.delete();
            return;
        }
        File[] files = root.listFiles();
        if (files != null) {
            for (File file : files) {
                delete(file);
            }
        }
        root.delete();
    }
}

Related

  1. cleanDirectory(File dir)
  2. cleanDirectory(File dir)
  3. cleanDirectory(File dir)
  4. cleanDirectory(File dir)
  5. cleanDirectory(File dir, boolean deleteDirectory)
  6. cleanDirectory(File directory)
  7. cleanDirectory(File directory)
  8. cleanDirectory(File directory)