Java file isFile()


 

Java file isFile()

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

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

Ads