在Java中操作Windows文件权限 [英] Manipulating Windows file permissions in Java
本文介绍了在Java中操作Windows文件权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Java如何操作Windows中文件的访问权限?
Using Java how could I manipulate the access permissions of a file in Windows?
推荐答案
如果您使用的是Java 6, File类为您提供setExecutable,setWritable等。请参阅: http ://java.sun.com/javase/6/docs/api/java/io/File.html
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
在较旧的Java版本上,这不是可能;你必须执行OS命令才能做到这一点:
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");
这篇关于在Java中操作Windows文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文