Java Delete Folder deleteFolder(File folder)

Here you can find the source of deleteFolder(File folder)

Description

delete Folder

License

Open Source License

Declaration

public static boolean deleteFolder(File folder) throws Exception 

Method Source Code

//package com.java2s;

import java.io.File;

public class Main {

    public static boolean deleteFolder(File folder) throws Exception {
        if (folder.exists()) {
            if (folder.isDirectory()) {
                File[] subFiles = folder.listFiles();
                for (File subFile : subFiles) {
                    if (subFile.isFile()) {
                        deleteFile(subFile);
                    } else {
                        deleteFolder(subFile);
                    }//w w  w . j  a v a  2s  .  c om
                }
            }
            return deleteFile(folder);
        } else {
            return false;
        }
    }

    public static boolean deleteFile(File file) throws Exception {
        if (file.exists()) {
            return file.delete();
        } else {
            return false;
        }
    }
}

Related

  1. deleteFolder(File folder)
  2. deleteFolder(File folder)
  3. deleteFolder(File folder)
  4. deleteFolder(File folder)
  5. deleteFolder(File folder)
  6. deleteFolder(File folder)
  7. deleteFolder(final File folder)
  8. deleteFolder(final File folder)
  9. deleteFolder(final String folder)