Home Tutorial Java Core Files Java file isDirectory()

 
 

Share on Google+Share on Google+
Java file isDirectory()
Posted on: June 17, 2006 at 12:00 AM
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
Advertisement

Related Tags for Java file isDirectory():


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.

Posted on: June 17, 2006

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com