我如何以编程方式更改文件权限? [英] How do i programmatically change file permissions?
问题描述
chmod
的Java。那可能是Java 5吗?如果是这样,怎么样? 我知道在Java 6中File对象具有setReadable()/ setWritable()方法。我也知道我可以做一个系统调用来做到这一点,但如果可能的话,我想避免这种情况。作为新新IO设施( =http://jcp.org/en/jsr/detail?id=203 =noreferrer> NIO.2 )。例如,可以使用 setPosixFilePermissions()
。
在早期的Java版本中,使用您自己的本地代码,或使用
exec
-ing命令行实用程序是常用的方法。 In Java, I'm dynamically creating a set of files and I'd like to change the file permissions on these files on a linux/unix file system. I'd like to be able to execute the Java equivalent of chmod
. Is that possible Java 5? If so, how?
I know in Java 6 the File object has setReadable()/setWritable() methods. I also know I could make a system call to do this, but I'd like to avoid that if possible.
Full control over file attributes is available in Java 7, as part of the "new" New IO facility (NIO.2). For example, POSIX permissions can be set with setPosixFilePermissions()
.
In earlier versions of Java, using native code of your own, or exec
-ing command-line utilities are common approaches.
这篇关于我如何以编程方式更改文件权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!