Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking For Directory Existance

 
Alan Jackson
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5093
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check the API docs for File. Everything you need is in there, it's only a few lines of code.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's java.io.File. See the "exists" method.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic