Given a file, and we have to check whether it is hidden or not using Java program?
File.isHidden()
This is a method of "File" class, which returns true if a file has hidden property and return false if it is not.
In this program, we are using a file named "includehelp.txt" which is stored in "E:\" in my system, program will check its hidden property and returns the result.
import java.io.*;
public class IsHidden {
public static void main(String[] args) {
// create file object.
File file = new File("E:/includehelp.txt");
// this will check is the file hidden or not.
boolean blnHidden = file.isHidden();
// return result in true or false condition.
System.out.println("Is the file " + file.getPath() + " hidden ?: " + blnHidden);
}
}
Output
Is the file E:\includehelp.txt hidden ?: false
Here, we are using an another method file.getPath() which returns the file name with path of that file, which is used while creating an object of “File” class.
Program to check file is hidden or not in java
Output
Here, we are using an another method file.getPath() which returns the file name with path of that file, which is used while creating an object of “File” class.