Java Delete Directory deleteDirectory(File file)

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

Description

delete Directory

License

Apache License

Declaration

public static void deleteDirectory(File file) throws IOException 

Method Source Code


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

import java.io.File;
import java.io.IOException;

public class Main {
    public static void deleteDirectory(File file) throws IOException {
        if (file.isDirectory()) {
            if (file.list().length == 0) {
                file.delete();//from w  w  w  .j  ava2s  .  co  m
            } else {
                String files[] = file.list();
                for (String temp : files) {
                    File fileDelete = new File(file, temp);
                    deleteDirectory(fileDelete);
                }
                if (file.list().length == 0) {
                    file.delete();
                }
            }
        } else {
            file.delete();
            System.out.println("File is deleted : " + file.getAbsolutePath());
        }
    }
}

Related

  1. deleteDirectory(File file)
  2. deleteDirectory(File file)
  3. deleteDirectory(File file)
  4. deleteDirectory(File file)
  5. deleteDirectory(File file)
  6. deleteDirectory(File fileOrDir)
  7. deleteDirectory(File root)
  8. deleteDirectory(File root)
  9. deleteDirectory(File root)