Java File Exist fileExists(final String pathname)

Here you can find the source of fileExists(final String pathname)

Description

File exists.

License

Open Source License

Parameter

Parameter Description
pathname the pathname

Return

true, if successful

Declaration

public static boolean fileExists(final String pathname) 

Method Source Code

//package com.java2s;
/*/*from  w ww.j a  v  a2s. com*/
 *  OpenBiomind-GUI: GUI for OpenBiomind
 *  Copyright (C) 2008  Bhavesh Sanghvi
 *
 *  This file (Utility.java) is part of OpenBiomind-GUI.
 *
 *  OpenBiomind-GUI 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.
 *
 *  OpenBiomind-GUI 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 OpenBiomind-GUI.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Please visit the following pages to contact the author(s):
 *  Homepage: http://code.google.com/p/openbiomind-gui/
 *  Mailing list: http://groups.google.com/group/openbiomind-gui/
 */

import java.io.File;

public class Main {
    /**
     * File exists.
     * 
     * @param pathname the pathname
     * 
     * @return true, if successful
     */
    public static boolean fileExists(final String pathname) {
        boolean valid = false;
        if (!isEmpty(pathname)) {
            final File file = new File(pathname);
            valid = file.exists() && file.isFile();
        }
        return valid;
    }

    /**
     * Checks if is the string empty.
     * 
     * @param string the string
     * 
     * @return true, if is empty
     */
    public static boolean isEmpty(final String string) {
        return (string == null || string.trim().isEmpty());
    }

    /**
     * Specifies if a file or directory specified by pathname exists or not?.
     * 
     * @param pathName the path name
     * 
     * @return true, if successful
     */
    public static boolean exists(final String pathName) {
        return (!isEmpty(pathName) && new File(pathName).exists());
    }
}

Related

  1. fileExists(File directory, String fileName)
  2. fileExists(File file)
  3. fileExists(File path)
  4. fileExists(final String path)
  5. fileExists(final String path)
  6. fileExists(String absolutePathAndFileName)
  7. fileExists(String aFilename)
  8. fileExists(String file)
  9. FileExists(String file)