The java source code presented on this sections shows how to check if file is hidden. This is a no brainer example since it just used the isHidden method of File class under java.lang package.

Check if file is hidden or not in java

There are three possible output of this java source code. There possible output are the following:

  • File is hidden
  • File is not hidden
  • File does not exist
package com.javatutorialhq.tutorial;

import java.io.File;

public class CheckHidden {

	/**
	 * This java sample code shows
	 * how to check if file is hidden
	 * Property of javatutorialhq.com
	 * All Rights Reserved
	 * Version 1.0
	 * 07/01/2012
	 */
	public static void main(String[] args) {
		File file = new File("C:\\temp\\test.log");
		if(file.exists()){
			if(file.isHidden()){
				System.out.println("File is hidden");
			}
			else{
				System.out.println("File is not hidden");
			}
		}
		else{
			System.out.println("File does not exist");
		}
	}
}