Java Delete Directory deleteDirectory(File directory)

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

Description

Delete all the files in a directory and then delete the directory itself.

License

Apache License

Parameter

Parameter Description
directory the directory to delete.

Declaration

static public void deleteDirectory(File directory) 

Method Source Code

//package com.java2s;
//   Licensed under the Apache License, Version 2.0 (the "License");

import java.io.File;

public class Main {
    /**/*w  w w  . j  a  v a 2 s. c o m*/
     * Delete all the files in a directory and then delete the directory itself.
     *
     * @param directory the directory to delete.
     */
    static public void deleteDirectory(File directory) {
        File[] firstDirectoryFiles = directory.listFiles();
        if (firstDirectoryFiles != null) {
            for (File file : firstDirectoryFiles) {
                file.delete();
            }
        }
        directory.delete();
    }
}

Related

  1. deleteDirectory(File directory)
  2. deleteDirectory(File directory)
  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)