Manipulating Windows file permissions in Java

前端 未结 2 880
Happy的楠姐
Happy的楠姐 2020-12-16 13:21

Using Java how could I manipulate the access permissions of a file in Windows?

相关标签:
2条回答
  • 2020-12-16 13:29

    If you are using Java 6, File class gives you setExecutable, setWritable, etc. See: http://java.sun.com/javase/6/docs/api/java/io/File.html

    On older Java versions this is not possible; you have to exec OS commands to do that:

    Windows:

    Runtime.getRuntime().exec("attrib -r myFile");
    

    Unix:

    Runtime.getRuntime().exec("chmod 777 myFile");
    
    0 讨论(0)
  • 2020-12-16 13:32

    The new Java 7 java.nio.file.attribute package makes all of this a lot easier. It provides views onto the complete set of file attributes, including Posix file permissions.

    0 讨论(0)
提交回复
热议问题