Mac文件系统操作全解析
1. 测试文件状态
在进行文件操作时,首先需要了解文件的状态,如文件是否存在、是否可读、可写、可执行以及是否可删除等。以下是具体的操作步骤:
1. 获取文件管理器和文件路径的引用:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *filePathName = @"/Users/Shared/textfile.txt";
- 测试文件是否存在:
BOOL fileExists = [fileManager fileExistsAtPath:filePathName];
if(fileExists)
NSLog(@"%@ exists", filePathName);
else
NSLog(@"%@ doesn't exist", filePathName);
- 测试文件是否可读:
BOOL fileIsReadable = [fileManager isReadableFileAtPath:filePathName];
if(fileIsReadable)
NSLog(@"%@ is readable", filePathName);
else
NSLog(@"%@ i
Mac文件系统操作详解
超级会员免费看
订阅专栏 解锁全文
2331

被折叠的 条评论
为什么被折叠?



