创建具有该组写入权限的目录 [英] Create directory with write permissions for the group
问题描述
我在我的java程序(在linux上运行)中创建了一个文件夹,其中包含File对象的mkdirs()函数。问题是该文件夹仅获取该组的读取权限。我需要它还具有写权限(以便以后能够删除它的文件)。有什么办法吗?
I create a folder in my java program (running on linux) with mkdirs() function of File object. The problem is that the folder gets only read permissions for the group. I need it to have also write permissions (in order to be able to delete its files later). What is the way to do it?
推荐答案
一个非常简单的解决方案是:
A very simple solution for this is:
file.setExecutable(true, false);
file.setReadable(true, false);
file.setWritable(true, false);
在上面的代码中,file是一个File对象。
In above code, file is a File object.
在创建文件集时,对文件 setExecutable(true)
的这些权限将允许您设置仅为所有者提供可执行文件
。如果你添加一个我在上面的代码中添加的参数 file.setExecutable(true,false);
将使可执行
false
仅限所有者,这意味着它将为所有组/世界设置权限。
When you are creating a file set these permissions to a file setExecutable(true)
will allow you to set that file as Executable
for owner only. If you add one more parameter which I have added in above code file.setExecutable(true, false);
will make Executable
false
for owner only, that means it will set permissions to all group / world.
在Debian和Windows XP上测试并使用。
Tested and working on Debian and Windows XP.
这篇关于创建具有该组写入权限的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!