Java File Delete delete(File aFile)

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

Description

deletes a file from the file system; for directories, recurse the subdirectories and delete them as well

License

Open Source License

Return

true if successful; false if any file or sub file could not be deleted

Declaration

public static boolean delete(File aFile) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2001, 2007 IBM Corporation and others.
 * 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
 *
 * Contributors://  w ww  . ja  va 2s  .  co m
 * IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.io.File;

public class Main {
    /**
     * deletes a file from the file system; for directories, recurse the subdirectories and delete
     * them as well
     * 
     * @return true if successful; false if any file or sub file could not be deleted
     */
    public static boolean delete(File aFile) {
        if (aFile == null)
            return true;
        if (aFile.isDirectory()) {
            File[] files = aFile.listFiles();
            if (files != null) {
                for (int i = 0; i < files.length; i++) {
                    if (!delete(files[i]))
                        return false;
                }
            }
        }
        return aFile.delete();
    }
}

Related

  1. clearFile(File file)
  2. clearFile(String directory)
  3. clearFile(String pFileName)
  4. clearFileOrDir(File file)
  5. delete(File classDir)
  6. delete(File current)
  7. delete(File dir)
  8. delete(File dir)