A Java program to demonstrate the use of java.io.File isHidden() to check if a file is hidden.

package com.favtuts.io.file;

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

public class FileHidden {
    public static void main(String[] args) throws IOException {
        //File file = new File("c:/hidden-file.txt");
        File file = new File("/home/tvt/.m2");
    	
    	if(file.isHidden()){
    		System.out.println("This file is hidden");
    	}else{
    		System.out.println("This file is not hidden");
    	}
    }
}

Note

The isHidden() method is system dependent, on UNIX platform, a file is considered hidden if it’s name is begins with a “dot” symbol (‘.’); On Microsoft Windows platform, a file is considered to be hidden, if it’s marked as hidden in the file properties.

Download Source Code

$ git clone https://github.com/favtuts/java-core-tutorials-examples

$ cd java-io/file

Leave a Reply

Your email address will not be published. Required fields are marked *