File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes how to check whether a file exists in a directory? 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 "how to check whether a file exists in a directory?" Watch "how to check whether a file exists in a directory?" New topic
Author

how to check whether a file exists in a directory?

Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
I have used my following code to find the directories under C:\\test\\loops and list them to get the display of directroies in my jsf page. Now I want to check whether every directroy contains one particulat text file by name properties.txt
If one directroy contains properties.txt, then I want to add that directory name into my HashMap test? How to do the modifications?


Thanks.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3939
    
  17

File has a constructor that takes a String for the file name and a directory the file should be found in. It also has a method to test if the file actually exists. You should be able to find out what you need by looking through the API


Steve
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
Yes I could figure out. Thanks.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3939
    
  17

Originally posted by Gopu Akraju:
Yes I could figure out. Thanks.


I would clean it up just a bit. I particularly find it important to change the constructor:

[ August 06, 2008: Message edited by: Steve Luke ]
 
 
subject: how to check whether a file exists in a directory?
 
Similar Threads
about properties.txt problem
store properties in webapps/ROOT/properties.txt
get directory name from the local file system