How do I know whether a given directory exists?
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sarah_Evans
Posted On:   Saturday, March 2, 2002 11:02 AM

Can I check whether a given directory exists or not using exists() method?

Re: How do I know whether a given directory exists?

Posted By:   AlessandroA_Garbagnati  
Posted On:   Monday, March 4, 2002 07:32 AM

Sarah,

You can also use the method isDirectory(), that is probably more appropriate in your case.

Re: How do I know whether a given directory exists?

Posted By:   Simon_Ablett  
Posted On:   Monday, March 4, 2002 07:28 AM

No offence (I wouldn't want to discourage people from asking questions)but if you know of the existence of the 'exists()' method might it not have been quicker and easier for you to simply right a quick test program to check if it worked? After all, the best way to learn a language is through use!! :-)

Regards.

Re: How do I know whether a given directory exists?

Posted By:   Anonymous  
Posted On:   Sunday, March 3, 2002 03:35 AM

Yes, because files and folders are both represented by the java.io.File class, you can simply test for the existence of a folder in this way:



File file = new File ( "/etc" );

file.exists ( ); // returns true


file = new File ( "/abcdef" );

file.exists ( ); // returns false



Hope this helps.


Regards,

G√ľnther
http://www.javacoding.net

About | Sitemap | Contact