Checking if a File Exists

Checking if a File Exists

Import java.nio.file.Files;
import java.nio.file.Paths;

public class CheckFileExistence {
    public static void main(String[] args) {
        String filePath = "example.txt";

        if (Files.exists(Paths.get(filePath))) {
            System.out.println("File exists!");
        } else {
            System.out.println("File does not exist.");
        }
    }
}

Related concepts

Checking if a File Exists

Checking if a File Exists — Structure map

Clickable & Draggable!

Checking if a File Exists — Related pages: