Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply

Java - canonical or absolute path?

 
Thread Tools Search this Thread
Old 01-23-2004, 06:47 AM   #1
Richard Chrenko
 
Posts: n/a
Default canonical or absolute path?

Although the Java SDK documentation defines "absolute" and "canonical"
paths, the practical meaning is not clear to me. For example, if I want my
application to save a list of "recent files", which should I use?
  Reply With Quote
Old 01-23-2004, 02:16 PM   #2
Steve W. Jackson
 
Posts: n/a
Default Re: canonical or absolute path?

In article <>,
Richard Chrenko <> wrote:

>:Although the Java SDK documentation defines "absolute" and "canonical"
>aths, the practical meaning is not clear to me. For example, if I want my
>:application to save a list of "recent files", which should I use?


I did some tinkering a few weeks ago with the two of them. While I'm
not 100% certain this is the distinction, I believe that what I found
was this. If a File object's path at creation has some kind of relative
reference used (such as ../otherdir/filename), then the canonical path
appeared to me to replace the ".." portion with the appropriate text.
The absolute path appeared to contain the path up to and including the
current working directory (or other source directory, depending on how
you created it, and then *included* the ".." portion, thus making it
longer.

If I'm correct in what I believe I understood, I would use canonical
paths wherever possible.

= Steve =
--
Steve W. Jackson
Montgomery, Alabama
  Reply With Quote
Old 01-23-2004, 04:46 PM   #3
Jon A. Cruz
 
Posts: n/a
Default Re: canonical or absolute path?

Steve W. Jackson wrote:
> In article <>,
> Richard Chrenko <> wrote:
>
>
>>:Although the Java SDK documentation defines "absolute" and "canonical"
>>aths, the practical meaning is not clear to me. For example, if I want my
>>:application to save a list of "recent files", which should I use?

>
>
> I did some tinkering a few weeks ago with the two of them.


Yup. That's pretty much it.

Absolute allows you to access the file from any current position, since
it's a path from the top of the file system. Canonical is 'the' way to
write a path, and should always be the same.

http://foldoc.doc.ic.ac.uk/foldoc/fo...uery=canonical

>
> If I'm correct in what I believe I understood, I would use canonical
> paths wherever possible.


Probably... but there is the gotcha that it can throw exceptions.

BTW, the javadoc for these methods have all those details.

http://java.sun.com/j2se/1.4.1/docs/...tAbsolutePath()

http://java.sun.com/j2se/1.4.1/docs/...CanonicalPath()

There are a few more things specified (like when a canonical path can
change), so you should read the docs.

  Reply With Quote
Old 01-23-2004, 04:59 PM   #4
Anton Spaans
 
Posts: n/a
Default Re: canonical or absolute path?

Conceptually, there is a rather big difference between canonical path and
absolute path.

This is what is usually understood by the word 'canonical':
- Values of Objects have representations, usually String representations
(from now on, I only will refer to them as String representations, since
they deal with user-input and user readable output). Each representation
must be *valid* for that particular object. However, one Object can have
multiple representations. For example, take an Integer that contains the
value 5. Valid representations are "5", "00005", "+5", "5.0", "0.5e+01",
etc. (invalid representations are "Hello", "QQlq"..hehehe). But there is
exactly 1 *canonical* representation of this Integer! The canonical
representation is one from the set of valid representations. Which one...?
That is usually agreed upon by commitees, drafts (RFCs), mathematical
notations, etc. In this case, the Integer's canonical representation would
be "5".

File-paths have something similar:
1- A file can have many relative paths.
2- Canonical paths are absolute paths.
3- An absolute path is not necessarly a canonical path! This holds true
especially under Unix, which support symbolic links. Under Windows, an
absolute path is usually a canonical path.

Example:
- A file with canonical path "/usr/somedir/subdir/file.txt"
- The 'current directory' is "/usr/somedir/subdir2"
- Subdir2 contains a symbolic link to this "file.txt" file, called "symlink"

Then these are valid relative paths to file.txt
"../subdir/file.txt", "../../somedir/subdir/file.txt",
"././././././file.txt"

These are valid absolute paths to file.txt:
"/usr/somedir/subdir/file.txt", "/usr/somedir/subdir2/symlink"

But only one out of all the valid paths is the canonical. It probably is
this one:
"/usr/somedir/subdir/file.txt"

How a canonical path is exactly defined for a File, you may have to check
from RFCs for that.

-- Anton Spaans.




"Richard Chrenko" <> wrote in message
news...
> Although the Java SDK documentation defines "absolute" and "canonical"
> paths, the practical meaning is not clear to me. For example, if I want my
> application to save a list of "recent files", which should I use?



  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript relative path to load xml file torontodesi Software 2 02-26-2009 12:13 PM
"src" path changing automatically?? lisaj Software 0 04-03-2008 10:36 AM
Get the Physical path of a sharpoint site arun_gp Software 0 07-31-2007 10:33 AM
how to upload a folder path??? chinna Software 0 10-03-2006 10:47 AM
Set default path of <input type = file> vj_india Software 1 09-15-2006 05:17 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47