-2

I have a scenario where I need to hide my some folders which contain some files. I search a lot over the internet but did not get any good solution. I need to hide subfolders not the whole directory. Here is the code which I am using

Process _p = null;
         try {
             _p = Runtime.getRuntime().exec("attrib +H " + t.getPath());
              _p.waitFor();
         } catch (IOException | InterruptedException ex) {
             java.util.logging.Logger.getLogger(newFrame.class.getName()).log(Level.SEVERE, null, ex);
         }

where t = path tp that file like C:\parentFolder\subfolder1\subfolder2\book.xml
I need to hide only subfolder1\subfolder2\book.xml

Please provide me some good solution.

Thanks in Advance.

Doctor Who
  • 747
  • 1
  • 5
  • 28

2 Answers2

2

Java 7 solution

Path path = Paths.get("your/folder");
Files.setAttribute(path, "dos:hidden", true);

Or:

Path path = Paths.get("your/folder");
DosFileAttributeView attr = Files.getFileAttributeView(path, DosFileAttributeView.class);
attr.setHidden(true);
Fred Porciúncula
  • 8,533
  • 3
  • 40
  • 57
1

use DosFileAttributeView , it has setHidden() method

http://docs.oracle.com/javase/7/docs/api/java/nio/file/attribute/DosFileAttributeView.html#setHidden(boolean)

Ramanlfc
  • 8,283
  • 1
  • 18
  • 24