In last article we saw how to check hidden files in Java and now we will see how to hide file in Java or make hidden file in Java. As we said File API in Java doesn’t provide any method to make a file hidden in Java but still you can apply some quick tricks to hide files from Java program. Like in Unix environment any file whose names begin with dot (.) is hidden so you can name your file starting with dot (.) and your File will be hidden in Linux or Unix Environment. On Windows you need to directly execute DOS command as stated in how to execute shell commands from Java by using Runtime.getRuntime.exec(“command”) to make the file hidden in Windows. Here is an example of making file hidden in Windows using Java Program.
Runtime.getRuntime().exec("attrib +H HiddenFileExample.java");