Java File Delete delete(File file)

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

Description

Delete a file or directory.

License

Apache License

Parameter

Parameter Description
file File, directory, or other filesystem artifact to delete.

Return

True if file was deleted, false otherwise.

Declaration

public static boolean delete(File file) 

Method Source Code

//package com.java2s;
// Licensed to the Apache Software Foundation (ASF) under one or more contributor

import java.io.File;

public class Main {
    /**//from   w  w w . ja  v a2s .  co m
     * Delete a file or directory.  If <var>file</var> references a directory, it
     * recursively deletes all the directory tree.
     *
     * @param file File, directory, or other filesystem artifact to delete.
     * @return True if <var>file</var> was deleted, false otherwise.
     */
    public static boolean delete(File file) {
        if (file.isDirectory()) {
            File[] entries = file.listFiles();
            if (entries != null) {
                for (File entry : entries) {
                    if (!delete(entry)) {
                        return false;
                    }
                }
            }
        }
        return file.delete();
    }
}

Related

  1. delete(File file)
  2. delete(File file)
  3. delete(File file)
  4. delete(File file)
  5. delete(File file)
  6. delete(File file)
  7. delete(File file)
  8. delete(File file)
  9. delete(File file)