Determine if File or Directory is hidden in Java


The method java.io.File.isHidden() is used to check whether the file or directory specified by the abstract path name is hidden in Java. This method returns true if the file or directory specified by the abstract path name is hidden and false otherwise.

A program that demonstrates this is given as follows −

Example


import java.io.File;
public class Demo {
   public static void main(String[] args) {
      try {
         File file = new File("c:/JavaProgram/demo1.txt");
         file.createNewFile();
         System.out.println(file.isHidden());
      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}

The output of the above program is as follows −

Output

false

Now let us understand the above program.

The method java.io.File.isHidden() is used to check whether the file or directory specified by the abstract path name is hidden and the boolean value that is returned by the method is printed. A code snippet that demonstrates this is given as follows −

try {
   File file = new File("c:/JavaProgram/demo1.txt");
   file.createNewFile();
   System.out.println(file.isHidden());
} catch(Exception e) {
   e.printStackTrace();
}

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

222 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements