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.
Here is the video tutorial of "How to check if a folder exists in Java?":
Code of this program is given below:
The output of the program is given below:
the file or directory you are searching does not exist : false
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: June 7, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles