Write a java program to Check file is Hidden or Not


This Java program checks whether a file named "file.txt" is hidden or not. First, the program creates a File object named file that represents the file "file.txt".

Then, it calls the isHidden() method on the file object, which returns true if the file is hidden, and false otherwise.

Finally, the program prints the result of the isHidden() method using the println() method, along with a message that indicates which file was checked.

Source Code

import java.io.*;
public class CheckFile
{
	public static void main(String[] args)
	{
		File file = new File("file.txt");
 
		boolean res = file.isHidden(); // check file is hidden or not
 
		// return result in true or false
		System.out.println("Is the file " + file.getPath() + " hidden ? : " + res);
	}
}

Output

Is the file file.txt hidden ? : false