• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Relativize question

 
Ranch Hand
Posts: 60
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given



Why does it print ..\Java.class and not .\Java.class
 
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Refer Java API 7 for Path link
 
Paul Statham
Ranch Hand
Posts: 60
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have seen that yes, in fact it even has this in the API

For example, if this path is "/a/b" and the given path is "/a/x" then the resulting relative path may be "../x"



I just don't understand why it would be .. and not .

All dealings with relative paths in the past have had . to mean current directory and .. as one level up

Or is it in fact saying for example if we just take



This would give

"Relativize: ../Java.class"

Relatively it is one level up from Java.java therefore the path is "../Java.class". Does that make sense?

 
Paul Statham
Ranch Hand
Posts: 60
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I have worked it out, I had to break it up into bullet points to understand it though. Here are some of my notes if it helps someone else

Path relativize(Path other)
- This method attempts to construct a relative path that when resolved against this path, yields a path that locates the same file as the given path
- Where this path and the given path do not have a root component, then a relative path can be constructed
- A relative path cannot be constructed if only one of the paths have a root component
- If this path and the given path are equal then an empty path is returned
- /a/b -> /a/b/c/d = c/d
- a/b -> a/b/c/d = c/d
- /a/b/c/d -> a/b = IllegalArgumentException
- /a/b/c/d -> /a/b = ../..
- /a/b -> /a/b = ""
- /a/b -> /a/c = ../c
- /x/d/g/a/b -> /a/b = ../../../../../a/b


 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic