Java Delete File deleteFile(String fileName)

Here you can find the source of deleteFile(String fileName)

Description

deleteFile Delete File

License

Open Source License

Parameter

Parameter Description
String FileName (FilePath)

Declaration

public static void deleteFile(String fileName) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Product: OSeB http://code.google.com/p/oseb                                *
 * Copyright (C) 2012 Mario Grigioni                                          *
 * This program is free software; you can redistribute it and/or modify it    *
 * under the terms version 2 of the GNU General Public License as published   *
 * by the Free Software Foundation. This program 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 General Public License for more details.                       *
 * You should have received a copy of the GNU General Public License along    *
 * with this program; if not, write to the Free Software Foundation, Inc.,    *
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.                     *
 *****************************************************************************/

import java.io.File;

public class Main {
    /**/*from www.  j av a2 s .  c o m*/
     *  deleteFile
     *  Delete File
     *  @param  String FileName (FilePath)
     */
    public static void deleteFile(String fileName) {
        File fp = new File(fileName);
        deleteFile(fp);
    }

    /**
     * deleteFile
     * @param File fp
     */
    public static void deleteFile(File fp) {

        boolean success = false;

        if (fp.isDirectory()) {
            File[] entries = fp.listFiles();
            for (File currentFile : entries) {
                deleteFile(currentFile);
            }
            success = fp.delete();
        } else {
            success = fp.delete();
        }

        if (!success)
            throw new IllegalArgumentException("Delete: deletion failed");
    }
}

Related

  1. deleteFile(String fileName)
  2. deleteFile(String filename)
  3. deleteFile(String fileName)
  4. deleteFile(String fileName)
  5. deleteFile(String fileName)
  6. deleteFile(String fileName)
  7. deleteFile(String fileName)
  8. deleteFile(String fileName)
  9. deleteFile(String filename)