How to make a folder hidden using java

If you’re using Java 7 you can use the new java.nio.file.attribute package like so:

Path path = FileSystems.getDefault().getPath("/j", "sa");
Files.setAttribute(path, "dos:hidden", true);

See more info at http://download.oracle.com/javase/tutorial/essential/io/fileAttr.html

Or, if you’re using an older version of Java and/or want to do it using Runtime, try this:

Process process = Runtime.getRuntime().exec("cmd.exe /C attrib -s -h -r your_path"); 

See more info on cmd and attrib.

Leave a Comment