aspose file tools
The moose likes Java in General and the fly likes What Does it Mean when a Directory's <list()> Returns <null>? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "What Does it Mean when a Directory Watch "What Does it Mean when a Directory New topic
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
    
    6

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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: What Does it Mean when a Directory's <list()> Returns <null>?
 
Similar Threads
list children of element (jdom)
TreeNode ClassCastException?
RefList help
Getting the arraylist through session
lists inside a list :(((