Java Reference
In-Depth Information
One thing that is “left out” of the list of roots is the so-called UNC filename. UNC filenames
are used on Microsoft platforms to refer to a network-available resource that hasn't been
mounted locally on a particular drive letter. For example, my server (running Unix with the
Samba SMB file server software) is named darian (made from my surname and first name),
and my home directory on that machine is exported or shared with the name ian , so I could
refer to a directory named book in my home directory under the UNC name \\dari-
an\ian\book . Such a filename would be valid in any Java filename context (assuming you're
running on Windows), but you would not learn about it from the File.listRoots() meth-
od.
Creating New Directories
Problem
You need to create a directory.
Solution
Use java.io.File 's mkdir() or mkdirs() method.
Discussion
Of the two methods used for creating directories, mkdir() creates just one directory, whereas
mkdirs() creates any parent directories that are needed. For example, if /home/ian exists and
is a directory, the calls:
new File("/home/ian/bin").mkdir( );
new File("/home/ian/src").mkdir( );
succeed, whereas:
new File("/home/ian/once/twice/again").mkdir( );
fails, assuming that the directory once does not exist. If you wish to create a whole path of
directories, you would tell File to make all the directories at once by using mkdirs() :
Search WWH ::




Custom Search