Java File Exist isFileExist(String sFileName)

Here you can find the source of isFileExist(String sFileName)

Description

File exist check

License

Apache License

Parameter

Parameter Description
sFileName File Name

Return

boolean true - exist
false - not exist

Declaration

public static boolean isFileExist(String sFileName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

public class Main {
    /**//from w  ww.j  a v  a 2  s  .c  om
     * File exist check
     *
     * @param sFileName File Name
     * @return boolean true - exist<br>
     *                 false - not exist
     */
    public static boolean isFileExist(String sFileName) {
        boolean result = false;

        try {
            File f = new File(sFileName);

            //if (f.exists() && f.isFile() && f.canRead()) {
            if (f.exists() && f.isFile()) {
                result = true;
            } else {
                result = false;
            }
        } catch (Exception e) {
            result = false;
        }
        /* return */
        return result;
    }
}

Related

  1. isFileExist(String file)
  2. isFileExist(String fileNameAndPath)
  3. isFileExist(String filePath)
  4. isFileExist(String filePath)
  5. isFileExist(String path)
  6. isFileExistByRegex(String dir, final String regex)
  7. isFileExisted(String filePathname)
  8. isFileExistent(String path)
  9. isFileExistNotCreate(String fileNameAndPath)