This is a very simple problem. You just have to determine whether a file or directory exists or not. If it exists it returns true otherwise in the else condition, it retunes vice-versa.
The following program creates an object of File class and checks whether the given file exists or not by using exists() method of the class.
We have used following methods:
exists(): It checks whether the file or directory denoted by this pathname exists or not.
Code of this program is given below:
import java.io.*;
|
The output of the program is given below:
| C:\java>java FileOrDirectoryExists the file or directory you are searching does not exist : false |
|
Recommend the tutorial |





Ask Questions? Discuss: Determining if a File or Directory exist View All Comments
Post your Comment