Search code examples
javapermissionsdirectoryshared

How do I modify permissions to a shared folder with java?


I have the following problem:

I have a shared folder on my computer(Windows OS). I need a script in Java that when runned blocks the acces of network users to this folder so that I am allowed to modify its content.

Any suggestions or ideas?


Solution

  • If you are using Java 7 or later, you could use the java.nio.Files.setAttribute to set the DOS permissions using the relevant attributes from the DosFileAttributeView.

    (You might also be able to do it using AclFileAttribute or PosixFileAttribute ... depending on the true nature of the folder you are attempting to modify.)

    For Java 6 or earlier, you would need to resort to a 3rd-party library, JNI/JNA calls, or using Process to run an external command.