Java Delete Folder deleteFolder(@Nonnull File file)

Here you can find the source of deleteFolder(@Nonnull File file)

Description

delete Folder

License

Open Source License

Declaration

public static boolean deleteFolder(@Nonnull File file) 

Method Source Code


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

import javax.annotation.Nonnull;
import java.io.*;

public class Main {
    public static boolean deleteFolder(@Nonnull File file) {
        if (file.exists()) {
            boolean result = true;

            if (file.isDirectory()) {
                File[] contents = file.listFiles();

                if (contents != null) {
                    for (File f : contents) {
                        result = result && deleteFolder(f);
                    }/*from w  w  w .  j  a  v a 2s .c o  m*/
                }
            }

            return result && file.delete();
        }

        return false;
    }
}

Related

  1. deleteFolder(File dir, boolean deleteFolderItself)
  2. deleteFolder(File file)
  3. deleteFolder(File file)
  4. deleteFolder(File file)