• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Path resolve method how it works?

 
Ranch Hand
Posts: 472
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When i read Mala Gupta book i found code example:

first i try this in Windows and get:

Microsoft Windows variant wrote:
\mydir\code\world\Hello.java
\world\Hello.java
E:\mydir\code
E:\OCPJavaSE7


next try this in Ubuntu and get:

Ubuntu (LINUX) variat wrote:
/mydir/code/world/Hello.java
/world/Hello.java
/mydir/code
/mydir/code/E:/OCPJavaSE7


(Ubuntu (LINUX) variant '/' - is absolute path and every line clear for me)

My question about line 6 and 8 of code (in Windows)

I can`t figure why result of this lines


\world\Hello.java
E:\mydir\code



i expected:


\mydir\code\world\Hello.java
E:\OCPJavaSE7\mydir\code



How '/' at begin of "/world/Hello.java" when passed to resolve considered?(especially for Windows where '/' is not root)
 
Sheriff
Posts: 9697
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know the exact reason why this is happening, but my guess is this is because you can do a cd / on Windows to go to the root of that drive (or do cd /temp to go to folder named temp in root of current drive). That's why when you specify a path starting with \ or / then it's considered as starting from the root of current drive. For example check these statements:

Note: If you start the path without the / then path.getRoot() returns null thus in such a case it resolves relative to current directory...
 
Sergej Smoljanov
Ranch Hand
Posts: 472
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this help . Thanks!
 
Something about .... going for a swim. With this tiny ad ...
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic