iphone 读写文件

来源:互联网 发布:华夏航空公司订票软件 编辑:程序博客网 时间:2024/05/22 17:58

- (void)readWritePlist:(BOOL)readonly{

//get the documents directory:

NSArray *paths =NSSearchPathForDirectoriesInDomains

(NSDocumentDirectory,NSUserDomainMask, YES);

NSString *documentsDirectory = [pathsobjectAtIndex:0];

//make a file name to write the data to using the

//documents directory:

NSString *fullFileName = [NSStringstringWithFormat:@"%@/arraydata.plist", documentsDirectory];

NSLog(@"fullFileName: %@",fullFileName);

//create an array and add values to it:

NSMutableArray *array = [[NSMutableArrayalloc] init];

[arrayaddObject:@"One"];

[arrayaddObject:@"Two"];

[arrayaddObject:@"Three"];

//this statement is what actually writes out the array

//to the file system:

[arraywriteToFile:fullFileName atomically:NO];

//retrieve the array contents.重新获取那个文件的内容

NSMutableArray *array2 = [[NSMutableArrayalloc] initWithContentsOfFile:fullFileName];

NSLog(@"readWritePlist: %@",array2);

[array2release];


原创粉丝点击