File isDirectory() method in Java with Examples
The isDirectory() function is a part of File class in Java . This function determines whether the is a file or directory denoted by the abstract filename is Directory or not.The function returns true if the abstract file path is Directory else returns false.
public boolean isDirectory()
Parameters: This method does not accept any parameter.
Return Value: The function returns boolean value representing whether the abstract file path is a directory or not
Exception: This method throws Security Exception if the read access to the file is denied
Below programs illustrates the use of isDirectory() function:
Example 1: The file “F:\\program.txt” is a existing file in F: directory .
Example 2: The file “F:\\program1” is a non existing directory in F: directory .
Not a Directory
Note: The programs might not run in an online IDE. Please use an offline IDE and set the path of the file.