wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Absolute and Canonical path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Absolute and Canonical path" Watch "Absolute and Canonical path" New topic
Author

Absolute and Canonical path

Vasiq Molvizadah
Ranch Hand

Joined: Dec 24, 2009
Posts: 66
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.


Human Knowledge Belongs to the World.
- Vasiq Mz
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Vasiq Molvizadah
Ranch Hand

Joined: Dec 24, 2009
Posts: 66
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.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Absolute and Canonical path