Using file.exists() to check the existence of a File in Java IO

Checking the existence of a file is easy in Java and is a method behind. The file.exists() method in does the thing. Here is a sample tutorial.

class FileExistence
public static void main(String args[])
File f=new File("myfile.txt");
// Print the name
System.out.println("The name of the file is "+f.getName());
// Does the file exist
System.out.println("Does the file exist? "+f.exists());
f.exists(): Check the existence of a file. If the file is present, it returns true else it returns false.

The name of the file is myfile.txt
Does the file exist? false


Posted by at on

Tags: Java IO,