我無法確定文檔文件夾中是否存在文件。即使我沒有將任何數據保存到使用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