首先查找document的存储路径,并设定具体存储路径
NSArray *pathArr=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *strPath=[pathArr lastObject];
NSString *strFinalPath=[NSString stringWithFormat:@"%@/myfile.txt",strPath];
整理写入数据NSData NSString NSArray
NSString *strData=@"hello,baby!";
NSData *data=[strData dataUsingEncoding:NSUTF8StringEncoding];
NSarray *arrData = [[NSArray alloc]initWithObjects:@"hello", @“baby” nil];
写入数据
BOOL bResult=[strData writeToFile:strFinalPath atomically:YES];
BOOL bResult=[data writeToFile:strFinalPath atomically:YES];
BOOL bResult=[arrData writeToFile:strFinalPath atomically:YES];
读取数据
NSData *readData=[[NSData alloc]initWithContentsOfFile:strFinalPath];
NSString *readStr=[NSString alloc]initWithContentsOfFile:strFinalPath encoding:NSUTF8StringEncoding error:]
NSArray *readArr=[NSArray alloc]initWithContentsOfFile:strFinalPath];