![]() |
|
|
|
#1 |
|
Posts: n/a
|
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? |
|
|
|
#2 |
|
Posts: n/a
|
In article <>,
Richard Chrenko <> wrote: >:Although the Java SDK documentation defines "absolute" and "canonical" > >: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 |
|
|
|
#3 |
|
Posts: n/a
|
Steve W. Jackson wrote:
> In article <>, > Richard Chrenko <> wrote: > > >>:Although the Java SDK documentation defines "absolute" and "canonical" >> >>: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. |
|
|
|
#4 |
|
Posts: n/a
|
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? |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |