November 2006
Intermediate to advanced
224 pages
3h 29m
English
File testPath = new File("directoryName"); boolean isDir = testPath.isDirectory(); if (isDir) { // testPath is a directory } else { // testPath is a file } |
In this phrase, we determine if a given File object represents a file or a directory. The isDirectory() method of the File class will return true if the File object on which it is called represents a directory, and it will return false if the File object represents a file.
This method is useful when you want to write a method that will traverse all of the files and directories under a given directory. Perhaps you want to write a method that will list all of the files under a specified directory and you want the method to recurse into all ...
Read now
Unlock full access