我无法确定文档文件夹中是否存在文件。即使我没有将任何数据保存到使用NSKeyedArchiver的文件中,我的测试也会返回true。 测试:iPhone - 保存和检索数据
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentPath = [documentsDirectory stringByAppendingPathComponent:@"gameData.dat"];
if ([fileManager fileExistsAtPath:documentPath]) {
//if the file exists retrieve the data.
//this is always called, even if there is no file at the documentPath.
}else{
//set the defaults and save data.
}
一旦从模拟器清除documentPath .. – ajay 2011-04-24 17:06:37