【发布时间】:2012-06-13 23:46:56
【问题描述】:
我正在尝试检查文件是否存在。如果我使用这个:
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:filePath]];
if (data == NULL){
...
}
我总是收到NULL。
比我找到的NSFileManager:
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:filePath])
按我的预期工作。是什么导致了这两个程序之间的差异?
【问题讨论】:
-
请注意,dataWithContentsOfURL: 返回 nil 并不一定意味着文件不存在——它只是意味着无法读取文件。
-
嘿,你给了我一个很好的观点!
标签: objective-c cocoa-touch nsdata nsfilemanager