exists and notExists

Alan Bateman Alan.Bateman at Sun.COM
Tue May 27 01:07:59 PDT 2008


Mark Thornton wrote:
> So in the case where existence can't be determined, both methods will 
> return false. I would prefer exists() to throw an exception which gave 
> the reason as accurately as possible. The existing File.delete() 
> method is very frustrating, as when it returns false there is a 
> laundry list of possible reasons but no clue as to which is true.
>
The checkAccess method does what you want. It checks the existence of a 
file and optionally its accessibility. It throws an exception and also 
documents a number of specific exceptions for specific cases. The 
exists/notExists methods that Elliotte is concerned about are 
convenience methods built on that.

Yes, File.delete is frustrating and many other methods have the same 
problem. We can finally fix these problems.

-Alan.





More information about the nio-discuss mailing list