清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
NSData *condata = responseObject; //设置编码格式,这种编码格式可以正常读取中文 NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); NSString *rcontent = [[NSString alloc]initWithData:condata encoding:enc]; NSLog(@"suceess %@",rcontent); NSString *filePath=[NSHomeDirectory() stringByAppendingFormat:@"/Documents/%@",[durl lastPathComponent]]; //输出文件完整路径,包括文件名 NSLog(@"filepath %@",filePath); NSData *incontent=[rcontent dataUsingEncoding:NSUTF8StringEncoding]; NSLog(@"ndata %@",incontent); //判断文件是否存在 if([[NSFileManager defaultManager]fileExistsAtPath:filePath]) { NSLog(@"yes or no"); //删除文件 [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil]; //想文件写入内容 [[NSFileManager defaultManager] createFileAtPath:filePath contents:incontent attributes:nil]; } //1、获得Documents文件夹路径 NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSLog(@"paths %@",paths); NSFileManager *fm=[NSFileManager defaultManager]; NSArray *file=[fm subpathsOfDirectoryAtPath:[paths objectAtIndex:0] error:nil]; NSString *df=[paths objectAtIndex:0]; //2、获得Documents文件夹路径 NSLog(@"sd %@",df); if(!df) { NSLog(@"not fd"); } else { NSLog(@"fd"); } NSString *filenam=[[paths objectAtIndex:0] stringByAppendingPathComponent:@"1.txt"]; //输出Documents文件夹下面1.txt文件的完整路径 NSLog(@"filennn %@",filenam); //检查Documents文件夹下面1.txt文件是否存在 if([[NSFileManager defaultManager] fileExistsAtPath:filenam]) { NSLog(@"find"); } //读取Documents文件夹下面1.txt文件的内容 NSData *read=[NSData dataWithContentsOfFile:filenam]; NSString *ss=[[NSString alloc] initWithData:read encoding:NSUTF8StringEncoding]; NSLog(@”ss”,%@",ss);