import java.io.File; public class FileExists { public static void main(String args[]) { //Creating a File object File file = new File("D:\\source\\sample.txt"); //Verifying if the file exits boolean bool = file.exists(); if(bool) { System.out.println("File exists"); }else { System.out.println("File does not exist"); } } }