我如何以编程方式更改文件权限? [英] How do i programmatically change file permissions?

查看:145
本文介绍了我如何以编程方式更改文件权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,我动态创建了一组文件,并且想要在linux / unix文件系统上更改这些文件的文件权限。我希望能够执行相当于 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆