Alex Rivera | Logout

Make a File/Folder Hidden on Windows with Java

Asked 2009-08-18T16:25:35.427
28

I need to make files and folders hidden on both Windows and Linux. I know that appending a '.' to the front of a file or folder will make it hidden on Linux. How do I make a file or folder hidden on Windows?

Edit
Report

2 Answers

20

Java 7 can hide a DOS file this way:

Path path = Paths.get("...");
Files.setAttribute(path, "dos:hidden", Boolean.TRUE, LinkOption.NOFOLLOW_LINKS);

Earlier Java versions don't have an API for this.

The above code will not throw an exception on non-DOS file systems. If the name of the file starts with a period, then it will be a hidden on UNIX file systems.

answered 2010-06-12T16:04:23.667
0
String cmd1[] = {"attrib","+h",file/folder path};
Runtime.getRuntime().exec(cmd1);

Use this code it might solve you problem

answered 2013-05-15T21:03:28.367

Your Answer