Java Reference
In-Depth Information
tem model. The earliest versions of MS-DOS didn't have directories, it just had “user num-
bers” like the system it was a clone of, Digital Research CP/M (itself a clone of various other
systems). So the Microsoft developers set out to clone the Unix filesystem organization. Un-
fortunately, they had already committed the slash character for use as an option delimiter, for
which Unix had used a dash ( - ); and the PATH separator (:) was also used as a “drive letter”
delimiter, as in C : or A :. So we now have commands like those shown in Table 2-1 .
Table 2-1. Directory listing commands
System Directory
list com-
mand
Meaning
Example PATH setting
Unix
ls -R /
Recursive listing of /, the top-level directory
PATH=/bin:/usr/bin
DOS
dir/s \
Directory with subdirectories option (i.e., recursive)
of \, the top-level directory (but only of the current
drive)
PATH=C:\windows;D:\mybin
Where does this get us? If we are going to generate filenames in Java, we may need to know
whether to put a / or a \ or some other character. Java has two solutions to this. First, when
moving between Unix and Microsoft systems, at least, it is permissive : either / or \ can be
used, [ 10 ] and the code that deals with the operating system sorts it out. Second, and more
generally, Java makes the platform-specific information available in a platform-independent
way. First, for the file separator (and also the PATH separator), the java.io.File class (see
Chapter 11 ) makes available some static variables containing this information. Because the
File class is platform dependent, it makes sense to anchor this information here. The vari-
ables are shown in Table 2-2 .
 
Search WWH ::




Custom Search