Java Directory Clear clearDirectory(File f)

Here you can find the source of clearDirectory(File f)

Description

clear Directory

License

Apache License

Declaration

public static void clearDirectory(File f) throws IOException 

Method Source Code


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

import java.io.*;

public class Main {
    public static void clearDirectory(File f) throws IOException {
        if (!f.isDirectory()) {
            throw new IllegalArgumentException("Only directory can be cleared."); // NOI18N
        }/*from   www. j a  v  a 2  s  . com*/
        for (File c : f.listFiles()) {
            delete(c);
        }
    }

    public static void delete(File f) throws IOException {
        if (f.isDirectory()) {
            for (File c : f.listFiles()) {
                delete(c);
            }
        }
        if (!f.delete()) {
            throw new IOException("Failed to delete file: " + f); // NOI18N
        }
    }
}

Related

  1. clearDirctory(File dir)
  2. clearDirectory(File dir)
  3. clearDirectory(File dir)
  4. clearDirectory(File dir, boolean doTree)
  5. clearDirectory(File f)
  6. clearDirectory(File src)
  7. clearDirectory(String absolutePath)
  8. clearDirectory(String dir)
  9. clearDirectory(String path)