Share on Google+Share on Google+

Java file isDirectory()

Advertisement
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

Advertisements

Posted on: June 17, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.