Java Examples - Hidden Directory


Advertisements


Problem Description

How to get a directory is hidden or not ?

Solution

Following example demonstrates how to get the fact that a file is hidden or not by using file.isHidden() method of File class.

import java.io.File;

public class Main {
   public static void main(String[] args) {
      File file = new File("C:/Demo.txt");
      System.out.println(file.isHidden());
   }
}

Result

The above code sample will produce the following result (as Demo.txt is hidden).

True

The following is an another example of directory is hidden or not in Java

import java.io.File;
import java.io.IOException;

public class FileHidden { 
   public static void main(String[] args) throws IOException { 
      File file = new File("C:\\Users\\TutorialsPoint7\\Desktop\\abc.txt");
      if(file.isHidden()) { 
         System.out.println("This file is hidden");
      } else { 
         System.out.println("This file is not hidden");
      } 
   }
}

The above code sample will produce the following result (as Demo.txt is hidden).

This file is not hidden

java_directories.htm

Advertisements