Check if a File is Hidden in Java

      No Comments on Check if a File is Hidden in Java




In Java, whether a file is hidden or not , it can be checked using isHidden() method of java.io.File.

Syntax of File isHidden() Method:

public boolean isHidden()

If a file is hidden then File isHidden() method returns true otherwise it returns false.

File object can refer to a directory or any other file.

Demo Program : File isHidden() Method

The below Program demonstrates how to check whether a file is hidden or not.

package com.masterjavatutorial;
import java.io.File;
public class Example {

	public static void main(String[] args) {

		 File file = new File("/srv/KT/Grunt.txt");
		 if(file.isHidden()){
		     System.out.println("File is Hidden");
		 }else{
		     System.out.println("File is not Hidden");
		 }
		 
		 File file1 = new File("/srv/softwares");
		 if(file1.isHidden()){
		     System.out.println("Directory is Hidden");
		 }else{
		     System.out.println("Directory is not Hidden");
		 }
	}

}