Java file isDirectory()


 

Java file isDirectory()

This section demonstrates you the use of isDirectory() method.

This section demonstrates you the use of isDirectory() method.

Java file isDirectory()

This section demonstrates you the use of isDirectory() method.

Description of code

Like isFile() method, isDirectory() method determines whether the pathname of the object represented by a File object is a directory. In other words, it determines if a File object is representing a directory. This method returns true if the object represented by the File object exists and is a directory otherwise it returns false.

Here is the code:

import java.io.*;

public class JavaIsDirectory {
	public static void main(String[] args) {
		File f = new File("C:/Text/");
		if (f.isDirectory()) {
			System.out.println("It is a directory");
		}
	}

}

Through the above code, you can check if a file object representing a directory.

Output:

It is a directory

Ads