Java Directory Delete nio deleteDirectory(File dir)

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

Description

delete Directory

License

Open Source License

Declaration

public static void deleteDirectory(File dir) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014,2015 Hideki Yatomi
 * All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/

import java.io.*;

import java.nio.file.*;

public class Main {
    public static void deleteDirectory(File dir) throws IOException {
        if (dir.exists() && dir.isDirectory()) {
            for (File child : dir.listFiles()) {
                if (child.isDirectory()) {
                    deleteDirectory(child);
                } else {
                    Files.delete(child.toPath());
                }/*w ww . j a  v  a2s  .  c o  m*/
            }
            Files.delete(dir.toPath());
        }
    }

    public static void delete(File file) throws IOException {
        Files.delete(file.toPath());
    }
}

Related

  1. deleteDir(File file)
  2. deleteDir(final File targetDir)
  3. deleteDir(String dirName)
  4. deleteDir(String path)
  5. deleteDirectory(File dir)
  6. deleteDirectory(File directory)
  7. deleteDirectory(File directory)
  8. deleteDirectory(File directory)
  9. deleteDirectory(File directory)