Java File Path Delete delete(File path)

Here you can find the source of delete(File path)

Description

deletes files and directories

License

Open Source License

Parameter

Parameter Description
path File

Declaration

public static void delete(File path) 

Method Source Code


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

import java.io.File;

public class Main {
    /**//from w ww .  j a  va2s .co  m
     * deletes files and directories
     *
     * @param path File
     */
    public static void delete(File path) {
        if (path.exists()) {
            if (path.isDirectory()) {

                File files[] = path.listFiles();
                for (File file : files) {
                    //delete each file in folder
                    delete(file);
                }

                //delete the folder
                path.delete();

            } else {
                //delete file i it is not a folder
                path.delete();
            }
        }
    }
}

Related

  1. delEmptyPath(String path)
  2. delete(File path)
  3. delete(File path)
  4. delete(File path)
  5. delete(File path)
  6. delete(File path, String... exclude)
  7. delete(final File path)
  8. delete(String fileNameWithFullPath)
  9. delete(String filePath)