This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File's list() method and classpaths

 
Denise Advincula
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Denis Bogdanov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is probably your problem:
taken from javadoc - JavaTM 2 Platform Standard Ed. 5.0

java.io.File->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
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic