0

Please look at this code snippet:

        Path path = Paths.get("followLink.lnk");
        System.out.println("path:" + path.toRealPath());
        System.out.println("path:" + path.toRealPath(LinkOption.NOFOLLOW_LINKS));

file with name followLink.lnk was created using following windows action:

mouse right click on file -> create shortcut

last two rows output are same and this information about shortcut. Is there way in nio2 obtain information about of source are pointed of shortcut ?

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

1 Answers1

3

toRealPath is for resolving symbolic links. Windows shortcuts are not symbolic links. You will have to open the .lnk file and read its contents to figure out where it points to.

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
  • Is there way in windows create symbolic link? – gstackoverflow Aug 06 '14 at 20:15
  • @gstackoverflow [Windows NTFS](http://en.wikipedia.org/wiki/NTFS) (2003+?) supports symbolic links, hardlinks, and directory junctions. See [`mklink`](http://www.sevenforums.com/tutorials/278262-mklink-create-use-links-windows.html) (I would expect the symbolic links to be supported under Java, but I've never tried.) – user2864740 Aug 06 '14 at 20:17
  • Messed situation about symbolic links and shortcuts – gstackoverflow Aug 06 '14 at 20:40