Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Doubt in getCanonicalPath

Thread view: 
RonRan - 21 Nov 2005 08:40 GMT
Hi,

The javadoc for the getCanonicalPath() method of java.io.File class
mentions the following :

"Every pathname that denotes an existing file or directory has a unique
canonical form. Every pathname that denotes a nonexistent file or
directory also has a unique canonical form. The canonical form of the
pathname of a nonexistent file or directory may be different from the
canonical form of the same pathname after the file or directory is
created. Similarly, the canonical form of the pathname of an existing
file or directory may be different from the canonical form of the same
pathname after the file or directory is deleted. "

Can someone please explain this with some concrete example? I am
confused as to how a nonexistent file can have a canonical path and
also how it may change when that file is created.

Thanks,
Rohan
adamspe@gmail.com - 21 Nov 2005 20:38 GMT
A non-existent file has to be able to have a canonical path.
java.io.File is only an abstract representation of a file name (or
directory name) regardless of whether the file exists or not.  It's
nothing but a holder for the reprepresentation of the path to a file
system object.

I'm guessing the bit of verbage surrounding canonical forms of existing
and non-existent paths has to do with OS-dependant features, probably
specifically case sensitivity on Win32.

On UNIX
/home/joeuser/MyFile
and
/usr/joeuser/myFile

are distinct and can co-exist without collisions

The same isn't true of a similar situation on Win32.

For example:

Say on Windows you have a non-existent file (or more appropriately
don't have)

String canonical = (new File ( "/tmp/NonExistent.txt"
)).getCanonicalPath();

On Windows, if the file didn't exist, would return something like
"C:\tmp\NonExistent.txt"

Say you then created that file but with case like "nonExistent.txt"

Runing the -exact- same bit of code above (no change in case on the
constructor) would result in a canonical representation of:

"C:\tmp\nonExistent.txt"
RonRan - 24 Nov 2005 08:35 GMT
hmm... thx for the help!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.