**plist文件其实就是XML文档,只是后缀名为plist。
如果对象是NSString、NSDictionary、NSArray、NSData、NSNumber等类型,就可以使用writeToFile:atomically:方法直接将对象写到属性列表文件中
**
关于plist文件的写入
- (void)saveArray
{
// 1.获得沙盒根路径
NSString *home = NSHomeDirectory();
// 2.document路径
NSString *docPath = [home stringByAppendingPathComponent:@"Documents"];
// 3.新建数据
NSArray *data = @[@"jack", @10, @"ffdsf"];
NSString *filepath = [docPath stringByAppendingPathComponent:@"data.plist"];
[data writeToFile:filepath atomically:YES];
}
关于plist文件的读取
- (IBAction)read {
// 1.获得沙盒根路径
NSString *home = NSHomeDirectory();
// 2.document路径
NSString *docPath = [home stringByAppendingPathComponent:@"Documents"];
// 3.文件路径
NSString *filepath = [docPath stringByAppendingPathComponent:@"data.plist"];
// 4.读取数据
NSArray *data = [NSArray arrayWithContentsOfFile:filepath];
NSLog(@"%@", data);
}