wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in files and Directories Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in files and Directories " Watch "doubt in files and Directories " New topic
Author

doubt in files and Directories

Divya Gehlot
Ranch Hand

Joined: Sep 10, 2006
Posts: 243
Hi,
I have doubt in getting list of files in a directory as in K&B book page 442 using list() function they are getting directory name also but I am not getting in my code shown as below. Is my correct or do I need to add anything to get dir name also?
Can any one help me in this.
correct me if I am wrong

Thanks in advance


SCJP1.5(81%), SCDJWS(94%), next mission SCEA (but need to wait or that)
Manfred Klug
Ranch Hand

Joined: Jun 04, 2007
Posts: 377
Hi Divya,

you request a list of all entries in directory mydir which only contains two files, file.txt and file2.txt. Which directory do you expect?
Murali Kakarla
Ranch Hand

Joined: Jul 11, 2007
Posts: 80
In the example on page 442 they are getting names of sub-directories and files under the directory 'searchThis'.

Since in your case you have only two files under 'mydir' it does not print any directory names.

Murali...
SCJP 5 Aspirant
Divya Gehlot
Ranch Hand

Joined: Sep 10, 2006
Posts: 243
Could you please tell me how to print directory name?
Murali Kakarla
Ranch Hand

Joined: Jul 11, 2007
Posts: 80
Divya,

I hope following example will clarify your doubt.



Murali...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: doubt in files and Directories
 
Similar Threads
renameTo()
NoClassDefFoundError
why it throws NullPointerException
Doubt in Renaming File
list of files in a directory