Check if a File is Hidden in Java
isHidden() method of File class in Java can use be used to check if a file is hidden or not. This method returns a boolean value – true or false.
public static boolean isHidden(Path path) throws IOException
Parameters: Path to the file to test.
Return Type: A boolean value, true if file is found hidden else returns false as a file is not found hidden
- 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.
Remember: Depending on the implementation the isHidden() method may require to access the file system to determine if the file is considered hidden.
Output Explanation: As it can easily be visualized from the background of the output that the ‘demo.rtf’ file popping icon is clearly seen. The code reflects that a specific file is not hidden on the terminal output as seen above.
Note: The precise definition of hidden is a platform or provider-dependent.
- UNIX: A file is hidden if its name begins with a period character (‘.’).
- Windows: A file is hidden if it is not a directory and the DOS hidden attribute is set.
This article is contributed by Saket Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.