Java Delete File deleteFile(final File file)

Here you can find the source of deleteFile(final File file)

Description

deletes recursevelly a directory

License

Open Source License

Parameter

Parameter Description
file the path of the directory to be deleted

Return

true is the directory was deleted or false if not

Declaration

public static boolean deleteFile(final File file) 

Method Source Code


//package com.java2s;
/*=========================================================================
    //w w w .j  a  v a 2s  .  co m
Copyright ? 2013 BIREME/PAHO/WHO
    
This file is part of TabNetCells.
    
TabNetCells is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 2.1 of
the License, or (at your option) any later version.
    
TabNetCells is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.
    
You should have received a copy of the GNU Lesser General Public
License along with TabNetCells. If not, see
<http://www.gnu.org/licenses/>.
    
=========================================================================*/

import java.io.File;

public class Main {
    /**
     * deletes recursevelly a directory
     * @param file the path of the directory to be deleted
     * @return  true is the directory was deleted or false if not
     */
    public static boolean deleteFile(final File file) {
        if (file == null) {
            throw new NullPointerException("file");
        }

        boolean status = true;

        if (file.isDirectory()) {
            for (File child : file.listFiles()) {
                status = status && deleteFile(child);
            }
        }
        return status && file.delete();
    }
}

Related

  1. deleteFile(File file)
  2. deleteFile(File source)
  3. deleteFile(final File f, final int attempts, final long sleepTime)
  4. deleteFile(final File file)
  5. deleteFile(final File file)
  6. deleteFile(final File file)
  7. deleteFile(final String dirname)
  8. deleteFile(Object fileObj)
  9. deleteFile(String archiveFilename)