• Post Reply Bookmark Topic Watch Topic
  • New Topic

Chapter 9 Q1 - relativize  RSS feed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I have a problem with explanation. If problems in this snippet was corrected it would be E.

So:


It prints:


/user/.././root/../kodiacbear.txt
/kodiacbear.txt
../lion



And i have a problem with understanding what exactly relativize method does. Why last line prints

../lion

when file kodiacbear.txt is in system root? What am i missing?
 
Marshal
Posts: 59146
180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume you know what an absolute path and a relative path mean. Have you read the documentation for Path#relativize(Path)? It isn't crystal clear, but it means how you would get from the end of this path to the target of the path passed as an argument. If you start from the location of the kodiacbear.txt file, and lion is in the same directory, ./lion will find the lion file.
 
Seba Doe
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would understand if the answer was ./lion (like you wrote) or /lion (like i thought)

But i am asking - why it's ../lion (double dots)
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!