| Author |
What Does it Mean when a Directory's <list()> Returns <null>?
|
Kevin Simonson
Ranch Hand
Joined: Oct 22, 2011
Posts: 52
|
|
I have some code I wrote quite a while ago that opens a <File> object, and that processes it differently depending on whether or not <isDirectory()> returns <true> or not. If it does return <true>, then it creates a <String[]> object named <children> and sets it equal to the value the <File> object's <list()> returns.
But then before my code actually does anything with <children>, it checks it to see if it equals <null>. What would it mean for the value returned by <list()> to be <null>? Is that an error condition I should check for?
The code I referred to is pretty complex, so I won't include it here, but if you need an example, here's a pretty simple one.
Kevin Simonson
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5901
|
|
Well, if you look at the docs, you'll see they say this:
Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Two common causes are a) the File object not being a directory (but that's not the case here), and b) the directory not being readable for you.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: What Does it Mean when a Directory's <list()> Returns <null>?
|
|
|