TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Checking File Or Directory in the System in Java Program
Alagunila Meganathan
Aug 03
2016
Code
484
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
FileOrDirectory.rar
import
java.io.*;
public
class
FileOrDirectoryExists{
public
static
void
main(String args[]){
File file=
new
File(
"Any file name or directory whether exists or not"
);
boolean
exists = file.exists();
if
(!exists) {
// It returns false if File or directory does not exist
System.out.println(
"the file or directory you are searching does not exist : "
+ exists);
}
else
{
// It returns true if File or directory exists
System.out.println(
"the file or directory you are searching does exist : "
+ exists);
}
}
}
JAva
File
Directory