Easy Tutorial
❮ Thread Monitor Arrays_Merge ❯

Java Example - Checking if a File Exists

Java Examples

The following example demonstrates how to use the file.exists() method of the File class to check if a file exists:

Main.java File

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());
    }
}

The above code will output the following result (if the file java.txt exists in your C drive):

true

Java Examples

❮ Thread Monitor Arrays_Merge ❯