Java File Exist fileExists(String filename)

Here you can find the source of fileExists(String filename)

Description

This checks to see if a file exists for the given path and throws a FileNotFoundException if the file does not exist.

License

Open Source License

Parameter

Parameter Description
filename The path to the file whose existence will be checked.

Exception

Parameter Description
FileNotFoundException if the file does not exist.

Declaration

public static void fileExists(String filename) throws FileNotFoundException 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    /**/* ww  w .j a  v  a  2  s  . c  o  m*/
    * This checks to see if a file exists for the given path and throws
    * a FileNotFoundException if the file does not exist.
    *
    * @param filename The path to the file whose existence will be checked.
    *
    * @throws FileNotFoundException if the file does not exist.
    */
    public static void fileExists(String filename) throws FileNotFoundException {

        File file = new File(filename);
        if (!file.exists()) {
            throw new FileNotFoundException("File [" + filename + "] does not exist.");
        }

    }
}

Related

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