Check whether the file is hidden or not in Java

Java 8Object Oriented ProgrammingProgramming

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

A program that demonstrates this is given as follows −

Example

 Live Demo

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

The output of the above program is as follows −

Output

Is file hidden? false

Now let us understand the above program.

The method java.io.File.isHidden() is used to check whether the given file specified by the abstract path name is a hidden file 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("demo1.txt");
   file.createNewFile();
   System.out.println("Is file hidden? " + file.isHidden());
} catch(Exception e) {
   e.printStackTrace();
}
raja
Published on 25-Feb-2019 12:01:31
Advertisements