Tutorialspoint examples

Learn java tutorial with examples for beginners online

check if a file is hidden java program


The isHidden() method of File class is used to check if a file is hidden in java. It returns true if the specified file is hidden else return false.

Example:

package com.tutorialspointexamples;
 
import java.io.File;
 
public class HiddenFileTest {
  public static void main(String args[]){
      try {
    	 //File
     	 File file = new File("D:/Test files/newTest.txt");
     	 //Check the file is writable or read only
     	 if(file.isHidden()){
     	    System.out.println("File is hidden.");
         }else{
     	    System.out.println("File is not hidden.");
     	 }
      } catch (Exception e) {
          e.printStackTrace();
      } 
  }
}

Output:

File is not hidden.

Download this example.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status