Home »
Java programming language
Java File Class boolean isHidden() method with Example
Java File Class boolean isHidden() method: Here, we are going to learn about the boolean isHidden() method of File class with its syntax and example.
Submitted by Preeti Jain, on July 08, 2019
File Class boolean isHidden()
- This method is available in package java.io.File.isHidden().
- This method is used to check whether the file is hidden or not.
- The return type of this method is Boolean i.e. The value of this method is true or false if it returns true that means the file is hidden else return false so the file is not hidden.
- This method may raise an exception(i.e. Security Exception) if the write access is not given to the file.
Syntax:
boolean isHidden(){
}
Parameter(s):
We don't pass any object as a parameter in the method of the File.
Return value:
The return type of this method is Boolean i.e. it returns true then in that case given file is hidden else returns false so the file is not hidden.
Java program to demonstrate example of isHidden() method
// import the File class because we will use File class methods
import java.io.File;
// import the Exception class because it may raise an
// exception when working with files
import java.lang.Exception;
public class ToCheckFileHidden {
public static void main(String[] args) {
try {
// Specify the path of file and we use double slashes to
// escape '\' character sequence for windows otherwise
// it will be considerable as url.
File file1 = new File("C:\\Users\\computer clinic\\OneDrive\\Articles\\myjava.txt");
File file2 = new File("C:\\Users\\computer clinic\\OneDrive\\Articles\\myjava1.txt");
// By using isHidden() is used to check whether the file
// is hidden or not . It returns true because given file is hidden.
if (file1.isHidden())
System.out.println("This file " + " " + file1.getName() + " " + "is hidden");
else
System.out.println("This file" + " " + file1.getName() + " " + "is not hidden");
// By using isHidden() is used to check whether the
// file is hidden or not. It returns false because given file
// is not hidden.
if (file2.isHidden())
System.out.println("This file " + " " + file2.getName() + " " + "is hidden");
else
System.out.println("This file " + " " + file2.getName() + " " + "is not hidden");
} catch (Exception e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}
Output
D:\Programs>javac ToCheckFileHidden.java
D:\Programs>java ToCheckFileHidden
This file myjava.txt is hidden
This file myjava1.txt is not hidden