Web | This Site

Java Basics Examples
Java Tutorial
Java Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM

| Home |  | References |  | Discussion Forums |  | About TP

# Java Examples - File Existance

## Problem Description:

How to check a file exist or not?

## Solution:

This example shows how to check a file’s existence by using file.exists() method of File class.

    import java.io.File;

    public class Main {
       public static void main(String[] args) {
          File file = new File("C:/java.txt");
          System.out.println(file.exists());
       }
    }

## Result:

The above code sample will produce the following result (if the file "java.txt" exists in 'C' drive).

    true

Advertisement

Online Image Processing

Indian Baby Names