How to check if a file is hidden in Java

Question:
How to check if a file is hidden in Java?

Answer:
Use the method isHidden() found in the class File.

Code:
import java.io.File;
import java.io.IOException;
 
public class HiddenFile {
 
   public static void main(String[] args) throws IOException { 
 
      File file = new File("/tmp/.hidden.txt");
 
      if(file.isHidden()) {
         System.out.println("File is hidden");
      } else {
         System.out.println("File is not hidden");
      }
   }
}

Output:
$ java HiddenFile
File is hidden

$ ls -l /tmp/.hidden.txt 
-rw-rw-r-- 1 dennis dennis 22 Feb 26 12:52 /tmp/.hidden.txt