Java File Path Delete deleteFile(String filePath)

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

Description

Delete the file targeted by the filePath

License

LGPL

Parameter

Parameter Description
String filePath

Return

Boolean isDeleted !!! the method returns false if : - the filePath targets a folder - the file does not exist - the file is locked

Declaration

public static boolean deleteFile(String filePath) 

Method Source Code


//package com.java2s;
/*/* ww  w. j  av  a2 s . co m*/
 * JLib - Publicitas Java library v1.2.0.
 *
 * Copyright (c) 2005, 2006, 2007, 2008, 2009 Publicitas SA.
 * Licensed under LGPL (LGPL-LICENSE.txt) license.
 */

import java.io.File;

public class Main {
    /**
     * Delete the file targeted by the filePath
     * @param String filePath
     * @return Boolean isDeleted
     * !!! the method returns false if :
     *     - the filePath targets a folder
     *     - the file does not exist 
     *     - the file is locked
     */
    public static boolean deleteFile(String filePath) {

        File fileToDelete = new File(filePath);

        if (!fileToDelete.isFile())
            return false;

        return fileToDelete.delete();
    }
}

Related

  1. deleteFile(final String dirPath, final String fileName)
  2. deleteFile(final String filePathName)
  3. DeleteFile(String _filePath)
  4. deletefile(String delpath)
  5. deleteFile(String filePath)
  6. deleteFile(String filePath)
  7. deleteFile(String filePath)
  8. deleteFile(String filePath)
  9. deleteFile(String filePath)