Java Reference
In-Depth Information
}
}
Forexample,whenIspecify
java PathnameInfo .
(theperiodrepresentsthe
current directory on my XP platform), I observe the following output:
Absolute path = C:\prj\dev\bj7\ch08\code\PathnameInfo\.
Canonical path = C:\prj\dev\bj7\ch08\code\PathnameInfo
Name = .
Parent = null
Path = .
Is absolute = false
This output reveals that the canonical pathname doesn't include the period. It also
shows that there's no parent pathname and that the pathname is relative.
Continuing, I now specify
java PathnameInfo
c:\reports\2011\..\2010\February
.Thistime,Iobservethefollowingout-
put:
Absolute path = c:\reports\2011\..\2010\February
Canonical path = C:\reports\2010\February
Name = February
Parent = c:\reports\2011\..\2010
Path = c:\reports\2011\..\2010\February
Is absolute = true
Thisoutputrevealsthatthecanonicalpathnamedoesn'tinclude
2011
.Italsoshows
that the pathname is absolute.
Formyfinalexample,supposeIspecify
java PathnameInfo ""
toobtainin-
formationfortheemptypathname.Inresponse,thisapplicationgeneratesthefollowing
output:
Absolute path = C:\prj\dev\bj7\ch08\code\PathnameInfo
Canonical path = C:\prj\dev\bj7\ch08\code\PathnameInfo
Name =
Parent = null
Path =
Is absolute = false
Theoutputrevealsthat
getName()
and
getPath()
returntheemptystring(
""
)
because the empty pathname is empty.