Share on Google+Share on Google+

Java file isFile()

Ads
This section demonstrates you the use of isFile() method.

Java file isFile()

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

Description of code

Java IO has provide several useful classes and methods. Among them, the method isFile() determines whether the pathname of the object represented by a File object is a file. In other words, it determines if a File object is representing a file. This method returns true if the object represented by the File object exists and is a file otherwise it returns false. It actually recognizes between files and directories. 

Here is the code:

import java.io.*;

public class JavaisFile {
	public static void main(String[] args) {
		File f = new File("C:/file.txt");
		if (f.isFile()) {
			System.out.println("It is a file");
		}
	}

}

Through the above code, you can check whether the file object representing the file.

It is a file

Advertisements

Ads

Posted on: August 7, 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.

Ads

Advertisement