File class exists() method example
Tests whether the file or directory denoted by this abstract pathname exists.
File class exists()method example. This example shows you how to use exists()method.This method Tests whether the file or directory denoted by this abstract pathname exists.
Here is the code:-
/**
* @Program that Tests whether the file or directory denoted by this abstract
* pathname exists.
* Exists.java
* Author:-RoseIndia Team
* Date:-30-May-2008
*/
import java.io.*;
public class Exists {
public static void main(String[] args) throws IOException {
File f=new File("/home/girish/Desktop/g.txt");
//Tests whether the file or directory denoted by this abstract pathname exists.
if(f.exists())
{
System.out.println("The file denoted by this abstract pathname exists.");
}
else
{
System.out.println("The file denoted by this abstract pathname cannot exists.");
}
}
} |
Output of the program:-
| The file denoted by this abstract pathname exists. |
|