How to Check If a File Is Hidden in Java


In this example we will show the method to check if a file is hidden in Java.

Source Code

package com.beginner.examples;

import java.io.*;

public class FileHidden {
  public static void main(String[] args) {

    File f = new File("example.txt");
    if (f.isHidden()) { // check if a file is hidden
      System.out.println("The file is hidden.");
    } else {
      System.out.println("The file is not hidden!");
    }
  }
}

Output:

The file is not hidden!
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments