• Post Reply Bookmark Topic Watch Topic
  • New Topic

resolve method java.nio.Path's method  RSS feed

Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thoroughly understand the use of resolve(path) and relativize(path). In the following snippet though there is something which is not very clear to me:

This snippet has been taken from here http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/essential/io/examples/Copy.java (preVisitDirectory method). I have slightly modified it as for changing name of target to destinationFolder.

If destinationFolder is /home/user/Desktop/Destination and source and dir (at least for the first recursive call) are /home/user/Desktop/ToBeCopied.

The result of destinationFolder will be /home/user/Desktop/Destination. This works fine and it is supercool however I cannot see why it gives back this outcome since source.relativize(dir); returns ../ToBeCopied and then with destinationFolder.resolve(../ToBeCopied) it should return (without normalizing it) /home/user/Desktop/Destination/../ToBeCopied hence /home/user/Desktop/ToBeCopied. Now if it was the case my program would not work, /ToBeCopied would self copy itself (if it makes sense). What actually happens is that in somehow the system takes the relative pattern used in source.relativize(dir) which is ../ToBeCopied and read something like "go back one step and then comeback" not like "go back one step and then back to /ToBeCopied". Why does it happen though? Logically should give back /home/user/Desktop/Destination/../ToBeCopied instead it returns /home/user/Desktop/Destination. What am I missing? Thanks a lot in advance!

PS: dir is the current directory of the recursive method preVisitDirectory and the first call will be exactly the same as the source itself.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!