O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Determining if a Filename Path is a File or Directory

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required