I want to create a hidden folder using java application. That program should work across platform. So How to write a program which can create hidden folder.
I have tried using
File newFile = new File("myfile");
newFile.mkdir();
It creates a directory which is not hidden.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With