How to check whether a file exist or not in java

  • by

Check whether a file exist or not:-
In system there are many files are existed. Bellow program used to determine whether a file is exist in your file system or directory. It is checked using file.exists() method. File.exists() method returns true if the file or directory exists, and false otherwise.
public class Main
public static void main(String[] args)
File file = new File(“C:/java.txt”);
System.out.println(file.exists()); // Check whether file a file exist or not


Leave a Reply