28
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.
String cmd1[] = {"attrib","+h",file/folder path};
Runtime.getRuntime().exec(cmd1);
Use this code it might solve you problem