Home Tutorial Java Core Files Java file isFile()

 
 

Java file isFile()
Posted on: August 7, 2006 at 12:00 AM
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

Related Tags for Java file isFile():


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.