To check whether the file exists or not, we have to import io package. And from this package, we have to import File Class.
import java.io.File;
File f = new File(filePathString); //filepath will be the directory path where you want to search a file
if(f.exists() && !f.isDirectory()) {
System.out.println("File exists");
}