Resolving empty paths.

Brendon McLean java.net at twistedprotein.com
Sun Jan 10 02:03:21 PST 2010


Alan,

I actually don't have a toFile method - I just made it up for the purposes of the example because the way I normally do that is more difficult to read and detracts from the usage of resolve that I was trying to highlight.  

Sorry for the confusion.  I copied this stuff before you added most of the file operation equivalents to the Path class, so I internally convert to File whenever I need to do anything useful.  I look forward to not having to do that.

Regards,
Brendon.

On 8 Jan 2010, at 17:53 , Alan Bateman wrote:

> Brendon McLean wrote:
>> :
>> Thanks.  It's just one of those use cases I need so often.  For example, if a user needs to create a sub path relative some "project path" then I end up code like this:
>> 
>> File f = projectPath.resolve(packageDir).resolve(file).toFile();
>> 
>> The empty package strikes again!  So obviously, I have to guard against it whenever I find this pattern emerging.
>>  
> Right, in the above then each invocation of resolve could throw InvalidPathException if the input is garbage.
> 
> Out of curiosity, is toFile() a method that you have added? This doesn't exist in our API as it wouldn't always make sense (for example the Path might locate a file in a custom file system).
> 
> -Alan.



More information about the nio-dev mailing list