NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [pathArray firstObject];
NSString *filePath = [documentPath stringByAppendingPathComponent:@"test.txt"];
// 写入文件
NSString *testStr = @"test....hello world!";
[testStr writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
// 读取文件
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSString *dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"DATASTR = %@", dataStr);