• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Absolute and Canonical path

 
Vasiq Molvizadah
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys...after reading many posts from javaranch and many other websites, I'm still not able to get the difference between Canonical and Absolute Path....so i wrote a program...



The output of the program is

Directory created.
The parent directory is C:\Directory\..\.
The path of the directory is C:\Directory\..\.\abc
The absolute path is C:\Directory\..\.\abc
The canonical path is C:\abc

I guess this program should create 2 directories one is "Directory" and "ABC" which should be inside "Directory" directory but it's creating only one which is "abc"...i'm not getting this Absolute and Canonical path thing...
Any help ....


Thanks for reading it.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Within File, the absolute path is not much more than the current folder added to the front of the path as you created the File with. For instance, if you create a new File("folder/../other") while your current folder is "D:\Temp", the absolute path will be "D:\\Temp\\folder\\..\\other".

The canonical file will ask the file system what the actual file path is. ".." means going up one path, "." means the current folder. In your case, It takes folder "C:\\Directory"", goes one up from that (resulting in "C:\\"), then goes to the same folder ("C:\\"), then goes to sub folder "abc" ("C:\\abc").

Note that you don't create any files or directories this way. They are all just names. Use mkdir() or mkdirs() to actually create directories.
 
Vasiq Molvizadah
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please explain me..what's the meaning of ".." and ".", while creating a directory or a file...
And in the program above...it only creates one directory which is "abc", i though it'll create two..directory 1. Directory 2. ABC.

btw thanks for the information.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic