在模拟器我可以一个NSMutableArray保存到一个文件,用下面的代码读回:保存的NSMutableArray到iPhone设备
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:@"RiskValues"]){ // If file exists open into table
NSLog(@"Risk Values File Exists");
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullFileName = [NSString stringWithFormat:@"RiskValues", documentsDirectory];
gRiskValues = [[NSMutableArray alloc] initWithContentsOfFile:fullFileName];
gRiskValuesAlreadyInitialised = YES;
} else {
NSLog(@"Can't find RiskValues file, so initialising gRiskValues table");
Do something else .......
}
这不会在设备上工作。我曾尝试使用下面找到该文件,但它仍然不能正常工作:
NSString *fullFileName = [documentsDirectory [email protected]"RiskValues"];
我在做什么错?
每个人都很棒的答案。我已经解决了文件路径和存在问题。非常感谢。