Deleting symbolic links via the java.nio.file.Path API

Alan Bateman Alan.Bateman at
Mon Jan 31 02:39:27 PST 2011

fm wrote:
> Sorry. I was being careless when I threw the checkAccess method into
> my conversation...I didn't think that one through. You are right,
> checkAccess does not seem to make sense for the symbolic links
> themselves (as opposed to their targets).
> However, I believe my concern with respect to checking the existence
> of symbolic links with the exists method is still reasonable.
> Just to provide another example. The following code throws a
> FileAlreadyExistsException when somePath corresponds to a broken
> symbolic link.
>    try {
>       if (!somePath.exists())       // or use somePath.notExists()
>          somePath.createFile();
>    }
>    catch (FileAlreadyExistsException e) {
>       System.err.println("File exists!?!");
>    }
>    catch (IOException e) { }
> Being able to call something like
> "somePath.exists(LinkOption.NOFOLLOW_LINKS)" would be helpful.
Just to follow up on this thread (from 10/2010). With the latest updates 
that were recently pushed then the exists method has the LinkOption[] 
parameter as discussed. This means that exists(path) will follow sym 
links, and exists(path, NOFOLLOW_LINKS) will not. Same thing for the 
isDirectory and isRegularFile methods. Thanks again for bringing this up.


More information about the nio-dev mailing list