-(void)saveDataToFile{
//存储数据
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [path objectAtIndex:0];
NSString *filePath = [documentDir stringByAppendingPathComponent:@"fps.csv"];
NSLog(@"filePath%@",filePath);
if (![[NSFileManager defaultManager]fileExistsAtPath:filePath]) {
[[NSFileManager defaultManager]createFileAtPath:filePath contents:nil attributes:nil];
}
NSMutableString *writeString = [NSMutableString stringWithCapacity:0];
NSMutableArray *dataArray = [NSMutableArray array];
for (int i=0; i<3; i++) {
NSString *s1 = [NSString stringWithFormat:@"row%d",i];
NSString *s2 = [NSString stringWithFormat:@"row%d",i];
NSString *s3 = [NSString stringWithFormat:@"row%d",i];
NSArray *rowArray = [NSArray arrayWithObjects:s1,s2,s3, nil];
NSLog(@"rowArray%@",rowArray);
[dataArray addObject:rowArray];
}
for (int j = 0; j < [dataArray count]; j++) {
[writeString appendString:[NSString stringWithFormat:@"%@;%@;%@\n",
[[dataArray objectAtIndex:j]objectAtIndex:0],
[[dataArray objectAtIndex:j]objectAtIndex:1],
[[dataArray objectAtIndex:j]objectAtIndex:2]]];
}
NSFileHandle *handle;
handle = [NSFileHandle fileHandleForWritingAtPath:filePath];
[handle truncateFileAtOffset:[handle seekToEndOfFile]];
[handle writeData:[writeString dataUsingEncoding:NSUTF8StringEncoding]];
}