File class - conversion from abstract pathname into...




1) File class presents an abstract, system-independent view of
hierarchical pathnames. So does that mean that conversion from
abstract pathname into string pathname is system dependent, and thus
the appropriate default separator is automatically used based on the
system this code runs on?

Let me elaborate what I mean:

“The conversion of a pathname string to or from an abstract pathname
is inherently system-dependent. When an abstract pathname is converted
into a pathname string, each name is separated from the next by a
single copy of the default separator character. The default name-
separator character is defined by the system property file.separator,”

a) My interpretation of the above paragraph is that if the following
code is run on Unix:

File f = new File (“A\\B\\C.txt”);

then Java will automatically change ( using default separator ) the
windows type of pathname into Unix type of pathname (“A/B/C.txt”).
Thus on Unix system, the above File object will represent file C.txt
and its path will be “A/B/C.txt”?!

b) But I imagine the following would cause an error on Unix, since
Java probably wouldn’t replace ‘C:\\’ prefix with ‘/’:

File f = new File(“C:\\A\\B\\C.txt”);

2) getCanonicalPathname() returns canonical path. What exactly is
canonical path and how does it differ from absolute and relative

thank you


OTOH, if you always used the *forward* slash, then you'd be fine. (Actually,
I don't know about Mac, but it'd be fine for Win and Unix/Linux.)
FWIW, I can confirm this for the Mac...


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Latest member

Latest Threads