Java IO

Make file hidden in Java example

Make file hidden in Java example shows how to make file hidden in Java. Example also shows how to check if file is hidden or visible.

How to check if file is hidden in Java?

Java File class provides isHidden method which can be used to check if the file is hidden or visible.

This method returns true if the file is hidden, false if the file is visible.



isHidden method may throw SecurityException if there is no read access to the file.

Note: Being hidden is platform dependent. If the file name starts with dot (“.”), for example .htaccess, it is considered to be hidden in Unix (*nix) systems. In Windows systems, hidden is an attribute of the file or directory.

How to make file hidden in Java?

There is no unified way to make files hidden using Java. Hidden has different meanings for different operating systems.

Make files hidden in Unix systems (*nix systems)

Simply renaming the files to have dot (“.”) as a first character of the file name will make the file hidden in Unix systems.

Make files hidden in Windows systems

There are a couple of ways to hide the files in Windows using Java. If you are using Java 7 or later version, you can use NIO’s attribute as given in below example.


If you are using older version of Java, you can still make the file hidden using Runtime class as given below.


Check out this example if you want to make file read only or refer to all file examples. Please let us know your views in the comments section below.


About the author



rahimv has over 15 years of experience in designing and developing Java applications. His areas of expertise are J2EE and eCommerce. If you like the website, follow him on Facebook, Twitter or Google Plus.


Your email address will not be published. Required fields are marked *