Java Delete Directory deleteDirectory(File directory)

Here you can find the source of deleteDirectory(File directory)

Description

delete Directory

License

Open Source License

Declaration

public static void deleteDirectory(File directory) 

Method Source Code


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

import java.io.*;

import java.util.*;

public class Main {
    public static void deleteDirectory(File directory) {
        if (directory != null) {
            deleteInDirectory(directory);
            directory.delete();/*from  w w w  .  j a  va  2s .co m*/
        }
    }

    public static void deleteInDirectory(File directory) {
        if (directory != null) {
            deleteInDirectoryApartFrom(directory);
        }
    }

    public static void deleteInDirectoryApartFrom(File directory, String... apartFrom) {
        if (directory != null) {
            Set<String> excluded = new HashSet<String>(Arrays.asList(apartFrom));
            for (File file : directory.listFiles()) {
                if (!excluded.contains(file.getName())) {
                    if (file.isDirectory()) {
                        deleteInDirectory(file);
                    }
                    file.delete();
                }
            }
        }
    }
}

Related

  1. deleteDirectory(File dir, boolean recursive)
  2. deleteDirectory(File dir, Map preserve)
  3. deleteDirectory(File directory)
  4. deleteDirectory(File directory)
  5. deleteDirectory(File directory)
  6. deleteDirectory(File directory)
  7. deleteDirectory(File directory)
  8. deleteDirectory(File directory)
  9. deleteDirectory(File directory)