File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes File's list() method and classpaths Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "File Watch "File New topic

File's list() method and classpaths

Denise Advincula
Ranch Hand

Joined: Jan 01, 2007
Posts: 163
I have this program from K&B (p.442):

My current directory is named "review", it has a subdirectory called "classes" wherein all classes are supposed to go. I compiled it using this command, and it compiles fine:

But when invoked using this command,

I get this error:

What gives?

I am always invoking in the same "review" directory. I am expecting that it would print out all the files in the classes directory (although I am not also sure if this would be true). I am trying to decipher what the "abstract pathname" is in the API about the list() method:

Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.

I hope anybody can help me. Thanks in advance!

SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCMJEA in progress...
Denis Bogdanov

Joined: Jul 10, 2008
Posts: 8
This is probably your problem:
taken from javadoc - JavaTM 2 Platform Standard Ed. 5.0>list(): ...If this abstract pathname does not denote a directory, then this method returns null ...

Check the string 7 - File search = new File("searchThis")
Denise Advincula
Ranch Hand

Joined: Jan 01, 2007
Posts: 163
I changed line 7 into this:

File search = new File("classes");

And it's now working. I see that the String specified in this line should represent an existing directory.

Thank you very much!
[ July 21, 2008: Message edited by: Denise Saulon ]
I agree. Here's the link:
subject: File's list() method and classpaths
It's not a secret anymore!