• Post Reply Bookmark Topic Watch Topic
  • New Topic

What Does it Mean when a Directory's <list()> Returns <null>?  RSS feed

 
Kevin Simonson
Ranch Hand
Posts: 223
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!