Java Folder Delete clearFolder(String folder)

Here you can find the source of clearFolder(String folder)

Description

clear Folder

License

Apache License

Declaration

public static void clearFolder(String folder) 

Method Source Code

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

import java.io.*;

public class Main {
    public static void clearFolder(String folder) {
        clearFolder(new File(folder));
    }//  ww  w. jav  a  2  s . c o m

    public static void clearFolder(File folder) {
        if (folder.exists()) {
            for (File child : folder.listFiles()) {
                if (child.isDirectory())
                    clearFolder(child);

                if (!child.delete())
                    throw new RuntimeException("Cannot delete " + child);
            }
        }
    }
}

Related

  1. clearFiles(File dir)
  2. clearFilesOnPath(String path)
  3. clearFolder(File f)
  4. clearFolder(File[] children)
  5. clearFolder(String directoryLocation)
  6. clearFolder(String path)
  7. clearFolderContent(String folderName)
  8. deepDelete(final File file)
  9. emptyAndDelete(File fileOrDir)