java在创建文件对象时将文件权限设置为777
可能的重复:
如何在 java 中设置 umask?
在java中创建文件对象时,如何将文件权限设置为777(或任何其他任意权限)?
Possible Duplicate:
How can I set the umask from within java?
How do you set file permissions to 777(or any other arbitrary permission) while creating a file object in java?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Java SE 7 有 java.nio.file .attribute.PosixFileAttributes 为您提供对所有者、组和其他人的读、写和执行权限的细粒度控制。
然后可以像这样使用:
Java SE 7 has java.nio.file.attribute.PosixFileAttributes which gives you fine grained control over read, write, and execute permissions for owner, group, and others.
Which can then be used like:
有 3 种方法可用:
setReadalble(布尔布尔值)
setWritable(boolean,布尔值)
setExecutable(boolean, boolean)
这会将文件设置为“0777”
3 methods are available:
setReadalble(boolean boolean)
setWritable(boolean,boolean)
setExecutable(boolean,boolean)
This will set the file to "0777"
如果在启动 JVM 之前将
umask(2)
设置为0
,则创建的所有文件和目录都将具有所有人的完全权限。这可能是一个坏主意。您可以使用
File.setReadable()
,
File.setWritable
创建文件后修改模式位的 API。如果您授予权限,这通常就足够了;如果您尝试删除其他用户的权限,那么您的权限可能应该从一开始就设置得非常严格。 (umask(0777)
在启动 JVM 之前,然后在您想要的位置添加权限。)If you set the
umask(2)
to0
before starting the JVM, all files and directories created will be created with full permissions for everyone. This is probably a bad idea.You can use the
File.setReadable()
,File.setWritable
APIs to fiddle with the mode bits after the file has been created. That's often good enough, if you're granting permissions; if you're trying to remove permissions from other users, then your permissions should probably be set very restrictively from the start. (umask(0777)
before launching the JVM, then add permissions exactly where you want them.)