isHidden() method of java.nio.file.Files help us to check whether or not a file is hidden. This method return true if the file is considered hidden else it returns false. The exact definition of hidden is platform or provider dependent.
On UNIX, for example, a file is considered to be hidden if its name begins with a period character (‘.’). On Windows, a file is considered hidden if it isn’t a directory and the DOS hidden attribute is set. Depending on the implementation this method may require to access the file system to determine if the file is considered hidden.
Syntax:
public static boolean isHidden(Path path)
throws IOException
Parameters: This method accepts a parameter path which is the path to the file to check.
Return value: This method returns true if the file is considered hidden.
Exception: This method will throw following exceptions:
- IOException: if an I/O error occurs
- SecurityException: In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the file.
Below programs illustrate isHidden(Path) method:
Program 1:
// Java program to demonstrate // Files.isHidden() method import java.io.IOException; import java.nio.file.*; public class GFG { public static void main(String[] args) { // create object of Path // This file is not hidden Path path = Paths.get( "D:\\GIT_EWS_PROJECTS\\logger" + "\\src\\logger" + "\\GFG.java"); // check whether this file // is hidden or not boolean result; try { result = Files.isHidden(path); System.out.println("File " + path + " is Hidden = " + result); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } |
Program 2:
// Java program to demonstrate // Files.isHidden() method import java.io.IOException; import java.nio.file.*; public class GFG { public static void main(String[] args) { // create object of Path // This file is available on windows and // It is hidden. Path path = Paths.get( "D:\\User Aman\\" + "Documents\\MobaXterm\\" + "\\ArrayList.docx"); // check whether this file // is hidden or not boolean result; try { result = Files.isHidden(path); System.out.println("File " + path + " is Hidden = " + result); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } |
Reference: https://docs.oracle.com/javase/10/docs/api/java/nio/file/Files.html#isHidden(java.nio.file.Path)
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- File isHidden() method in Java with Examples
- Files deleteIfExists() method in Java with Examples
- Files delete() method in Java with Examples
- Files getFileStore() method in Java with Examples
- Files isReadable() method in Java with Examples
- Files isWritable() method in Java with Examples
- Files isExecutable() method in Java with Examples
- Files size() method in Java with Examples
- Compressing and Decompressing files in Java
- Jar files in Java
- Working with JAR and Manifest files In Java
- How to rename all files of a folder using Java?
- Compressing and Decompressing files using GZIP Format in java
- Java program to merge two files into a third file
- Java program to merge two files alternatively into third file
- Java program to List all files in a directory and nested sub-directories | Recursive approach
- Java program to merge two files alternatively into third file
- Java program to merge contents of all the files in a directory
- How to find and open the Hidden files in a Directory using Java
- How to get a list of files from the FTPserver?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

