Java Delete File deleteFile(String fileName)

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

Description

delete a file from the system, if exists

License

Open Source License

Parameter

Parameter Description
fileName the file to delete (full path)

Return

false if file doesn't exist or is a directory

Declaration

public static boolean deleteFile(String fileName) 

Method Source Code

//package com.java2s;

import java.io.File;

public class Main {
    /**//w  w  w  . j a v  a  2s  .c om
     * delete a file from the system, if exists
     * 
     * @param fileName
     *            the file to delete (full path)
     * @return false if file doesn't exist or is a directory
     */
    public static boolean deleteFile(String fileName) {
        File file = new File(fileName);
        if (!file.exists() || file.isDirectory()) {
            return false;
        }
        file.delete();
        return true;
    }

    public static boolean exists(String fileName) {
        File file = new File(fileName);

        return file.exists();
    }
}

Related

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