如何获取
下保存的文件-(NSString *) dataFilePath
{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path objectAtIndex:0];
return [documentDirectory stringByAppendingPathComponent:@"Answer.plist"];
}
NSString *filePath = [self dataFilePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{ NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
NSLog(@"%@\n",array);
NSLog(@"%@\n", filePath);
}
并且有没有办法在没有覆盖的情况下向plist添加项目?
答案 0 :(得分:1)
您可以使用:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
path = [documentsDirectory stringByAppendingPathComponent:@"Answer.plist"];
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSLog(@"array, %@",array);
[array removeObjectAtIndex:yourIndex];
或
[array addObjectAtIndex:yourIndex];
[array writeToFile:path atomically:YES];