Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
828 views
in Technique[技术] by (71.8m points)

io - How to make a folder hidden using java

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...