Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Checking For Directory Existance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Checking For Directory Existance" Watch "Checking For Directory Existance" New topic
Author

Checking For Directory Existance

Alan Jackson
Greenhorn

Joined: Oct 26, 2004
Posts: 26
Im using some code to list the contents of a directory as a string, and Im wanting to add in some fail safes.

How would I go about checking if the directory exists first of all? If it doesnt exist, I want to output a message saying it doesnt exist.

Similarly, if the directory is empty I want to ouput that too.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
check the API docs for File. Everything you need is in there, it's only a few lines of code.


42
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

That's java.io.File. See the "exists" method.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checking For Directory Existance
 
Similar Threads
commenting a gif
After deploying page doesn't change
Pathname Validation - Please help out!!!
file upload in servlet
Check if File is Folder