Manipulating Windows file permissions in Java

前端 未结 2 881
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");
    

提交回复
热议问题