Java在创建文件对象时将文件权限设置为777 [英] java set file permissions to 777 while creating a file object

查看:1866
本文介绍了Java在创建文件对象时将文件权限设置为777的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何从Java内部设置umask?

Possible Duplicate:
How can I set the umask from within java?

在Java中创建文件对象时如何将文件权限设置为777(或任何其他任意权限)?

How do you set file permissions to 777(or any other arbitrary permission) while creating a file object in java?

推荐答案

如果在启动JVM之前将umask(2)设置为0,则创建的所有文件和目录将对所有人具有完全权限.这可能是个坏主意.

If you set the umask(2) to 0 before starting the JVM, all files and directories created will be created with full permissions for everyone. This is probably a bad idea.

您可以使用 File.setReadable() File.setWritable API来创建文件后,用模式位来摆弄.如果您授予权限,那通常就足够了;如果您要尝试删除其他用户的权限,则可能应该从一开始就非常严格地设置您的权限. (umask(0777)在启动JVM之前,然后将权限添加到您想要的位置.)

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.)

这篇关于Java在创建文件对象时将文件权限设置为777的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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