Java File Exist fileExists(String path, boolean throwException)

Here you can find the source of fileExists(String path, boolean throwException)

Description

file Exists

License

Apache License

Declaration

public static boolean fileExists(String path, boolean throwException) throws FileNotFoundException 

Method Source Code


//package com.java2s;
/*//w  w w  . j av a 2s.  c o m
 * EBI MetaboLights - http://www.ebi.ac.uk/metabolights
 * Cheminformatics and Metabolism group
 *
 * European Bioinformatics Institute (EMBL-EBI), European Molecular Biology Laboratory, Wellcome Trust Genome Campus, Hinxton, Cambridge CB10 1SD, United Kingdom
 *
 * Last modified: 4/11/14 5:12 PM
 * Modified by:   conesa
 *
 *
 * ?, EMBL, European Bioinformatics Institute, 2014.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 */

import java.io.*;

public class Main {
    public static boolean fileExists(String path) {
        File file = new File(path);

        return file.exists();
    }

    public static boolean fileExists(String path, boolean throwException) throws FileNotFoundException {

        return fileExists(new File(path), throwException);

    }

    public static boolean fileExists(File file, boolean throwException) throws FileNotFoundException {

        boolean result = file.exists();

        if (throwException && !result) {

            throw new FileNotFoundException("Path (" + file.getAbsolutePath() + ") not found.");
        }

        return result;

    }
}

Related

  1. fileExists(String path)
  2. fileExists(String path)
  3. fileExists(String path)
  4. fileExists(String path)
  5. fileExists(String path)
  6. fileExists(String path, String fileName)
  7. fileExists(String s)
  8. fileExistsAndCanRead(final String filePath)
  9. fileExistsAndIsExecutable(String filePathString)