This article is quick tip to find hidden files in Java by checking hidden properties of a File or directory from Java Program. File Handling is a crucial topic in java already we have discussed about how to create file in java , how to create directory, how to read write in a text file in Java , how to set permissions on file and some more aspect and we will discuss one more property of file, i.e. hidden property. Now the question arise can we make a file Hidden using our java code or not. So the answer would be No-using java File API it’s not possible to make any file hidden because it’s a OS or platform dependent property.
· If we are working in UNIX environment then file is considered as Hidden if its name begins with “.”
· And if we are dealing with Windows environment then a file is hidden if we set file hidden property, and also it’s should not be a directory.
So now we are clear that we can’t write code for making a file hidden directly from Java File API but what we can do is after making any file hidden depending upon the platform we can check the file property is hidden or not and accordingly we can use that file in our application. isHidden() method is provided on file Class in Java which we will use to test this property.
Syntax of the method:
public static boolean isHidden(Path path) throws IOException
How To check Hidden property of file in Java-isHidden ()Method
Here we pass the path of the file for which we want to test hidden property and it will return true if it’s a hidden file otherwise will get false value.
Here is complete code example of finding hidden file in Java, we are using file.isHidden() method to check whether a file is hidden or not.
Some other Java Tutorial you may like: