Java.io.File.isHidden() Method

Advertisements


Description

The java.io.File.isHidden() checks whether the file named by this abstract pathname is a hidden file.

Declaration

Following is the declaration for java.io.File.isHidden() method:

public boolean isHidden()

Parameters

  • NA

Return Value

The method returns true if and only if the file named by this abstract pathname is a hidden file else the method returns false.

Exception

  • SecurityException -- If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file

Example

The following example shows the usage of java.io.File.isHidden() method.

package com.tutorialspoint;

import java.io.File;

public class FileFreeSpace {
   public static void main(String[] args) {
      
      File f = null;
      String path;
      boolean bool = false;
      
      try{      
         // create new file
         f = new File("c:/test.txt");
         
         // true if the file path is a hidden file
         bool = f.isHidden();
         
         // get the path
         path = f.getPath();
         
         // prints
         System.out.print(path+" is file hidden? "+bool);
         
      }catch(Exception e){
         // if any error occurs
         e.printStackTrace();
      }
   }
}

Let us compile and run the above program, this will produce the following result:

c:\test.txt is file hidden? false



Advertisements
Advertisements