Java File Path Delete deleteIfExist(String filePath)

Here you can find the source of deleteIfExist(String filePath)

Description

Delete the file/directory if exist.

License

Open Source License

Parameter

Parameter Description
filePath - The path of the file/directory to delete.

Declaration

public static void deleteIfExist(String filePath) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 MCForge.//  ww  w . j  av  a  2  s  . c o  m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 ******************************************************************************/

import java.io.File;

public class Main {
    /**
     * Delete the file/directory if exist.
     * 
     * @param filePath - The path of the file/directory to delete.
     */
    public static void deleteIfExist(String filePath) {
        File file = new File(filePath);
        if (file.exists()) {
            file.delete();
        }
    }

    /**
     * Checks whether the specified file exists
     * 
     * @param filePath - the file path to check
     */
    public static boolean exists(String filePath) {
        return new File(filePath).exists();
    }
}

Related

  1. deleteFolder(String pFolderPath)
  2. deleteFolder(String sPath)
  3. deleteFolderAndContent(String folderPath)
  4. deleteFolderRec(File path, boolean alsoDeleteGivenFolder)
  5. deleteFolderRecursively(File path, boolean includeSelf)
  6. deleteInPathTempFiles(String workingFolder)
  7. deleteInRemote(String host, String path)
  8. deleteJaasFile(String jaasPath)
  9. deleteKey(String path, String key)