我有一个使用NSFileManager创建的文件,但找不到将其设置为只读的方法。我已经在整个互联网和Apple的NSFileManager Class Reference中进行了搜索,但找不到任何内容。这是文件创建位置的代码。

if ([fm createFileAtPath:fileName contents:inputData attributes:nil] == NO) {
     NSLog(@"Error!");
     return 1;
}

最佳答案

使用setAttributes:[NSFileManager defaultManager]删除文件读取位。 This帖子对此进行了解释。

以下将权限设置为-rwxrwxrwx(0777)。将0777替换为所需的权限。

NSDictionary *attributes;
[attributes setValue:[NSNumber numberWithShort:0777] forKey:NSFilePosixPermissions];
[[NSFileManager defaultManager] setAttributes:attributes ofItemAtPath:@"/path/to/file"]

关于objective-c - NSFileManager-创建一个只读文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29476096/

10-12 05:39