Ok... I'm a bit confused as to the behavior of java.io.File.exists() but maybe I'm just missing something basic... Modify the below code to point to a file that exists on your machine, why do both files print true? that they exist? even though there is no directory called 'C:\stuff\blah.\' on my machine??
[ February 20, 2002: Message edited by: Jessica (Bradley) Sant ]
... just to answer my own question -- turns out it's OS specific. Windows strips out the '.' at the end of the file name because Windows doesn't allow a '.' at the end of a file name --> try creating a folder called "blah." in Windows -- it will stip out the '.' and you'll end up with a folder called "blah" don't we all just love Windows.
Don't cha just love an OS that thinks it's smarter than you? I hate all the places that Windoze thinks "Oh, I know what the user REALLY wanted to do". It makes writing code so much more interesting. Glad you found the error. That was an interesting issue to find.
For a good Prime, call:<br />29819592777931214269172453467810429868925511217482600306406141434158089
So... it might not just be Microsoft screwing with me on this one... one of the guys here at work pointed this out... and thinks this actually has its origin back in DOS. In DOS you can call dir *. -- to give you a listing of only the directories. Because DOS assumed anything without an extension was a directory. hmmmm
Originally posted by Jessica (Bradley) Sant: So... it might not just be Microsoft screwing with me on this one... one of the guys here at work pointed this out... and thinks this actually has its origin back in DOS.
Jessica, just out of interest cause i never could figure it out by the documentaion, what is the difference between the absolute and the canonial paths??? i cant see any difference in the output between those two, even though their description is diffreent.
Hi, To get a feel of the differences between the 2 calls, you can try File file = new File("c:\\abc\\def\\..\\.\\filename.txt"); System.out.println(file.getAbsolutePath()); System.out.println(file.getCanonicalPath()); Of course, you'll need to substitute abc and def with valid path. Then you should see c:\abc\def\..\.\filename.txt c:\abc\filename.txt Hope this helps. Cheers.
Roy Ben Ami
Joined: Jan 13, 2002
thanks Han Ming, but whats the use for the Canonical path? why do we need it? is it because of the diffrence between platforms like unix and windows treat directories structure.
getAbsolutePath() -- gets the absolute (complete) pathname of the file. getCanonicalPath() -- gets the absolute pathname with all references resolved. Like HanMing showed in his example, getCanonicalPath() will resolve "\..\" (a reference to the parent directory) to the actual name of the directory. And in the case I actually started this thread with... it finds that "D:\\stuff\\blah.\\Factorial.java" is REALLY the file "D:\\stuff\\blah\\Factorial.java" -- which is what I needed it to do.