Java Delete File if Exist deleteIfExists(File file)

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

Description

Loescht die angegebene Datei falls sie existiert.

License

Open Source License

Parameter

Parameter Description
file Zu loeschende Datei

Return

Wahr, falls die Datei nicht existiert oder sie existiert und erfolgreich geloescht (d.h. file.delete()==true) werden konnte, falsch sonst.

Declaration

public static boolean deleteIfExists(File file) 

Method Source Code

//package com.java2s;
/*/* ww  w  .j  a v a2 s .  c  o  m*/
 * Copyright 2005-2008 by beck et al. projects GmbH, Munich
 * Copyright 2009 by Kappich Systemberatung, Aachen
 * 
 * This file is part of de.bsvrz.sys.funclib.losb.
 * 
 * de.bsvrz.sys.funclib.losb is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * de.bsvrz.sys.funclib.losb 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 de.bsvrz.sys.funclib.losb.  If not, see <http://www.gnu.org/licenses/>.
    
 * Contact Information:
 * Kappich Systemberatung
 * Martin-Luther-Stra?e 14
 * 52062 Aachen, Germany
 * phone: +49 241 4090 436 
 * mail: <info@kappich.de>
 */

import java.io.File;

public class Main {
    /**
     * Loescht die angegebene Datei falls sie existiert.
     *
     * @param file Zu loeschende Datei
     *
     * @return Wahr, falls die Datei nicht existiert oder sie existiert und erfolgreich geloescht (d.h. <code>file.delete()==true</code>) werden konnte, falsch
     *         sonst.
     */
    public static boolean deleteIfExists(File file) {
        if (file.exists()) {
            return file.delete();
        } else {
            return true;
        }
    }
}

Related

  1. deleteIfExists(File f)
  2. deleteIfExists(File file)
  3. deleteIfExists(File file)
  4. deleteIfExists(final File file)
  5. deleteIfExists(final File file)
  6. deleteIfExists(java.io.File file)