沙盒文件的创建(简单举例)
程序员文章站
2023-09-09 00:03:51
//创建文件 NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSFileManager *fileManager = [NSFileManager def... ......
//创建文件 nsstring *documentsdirectory = [nshomedirectory() stringbyappendingpathcomponent:@"documents"]; nsfilemanager *filemanager = [nsfilemanager defaultmanager]; nsstring *filepath = [documentsdirectory stringbyappendingpathcomponent:@"xxx.txt"]; nslog(@"-----%@",filepath); if(![filemanager fileexistsatpath:filepath]) //如果文件xxx不存在 { nslog(@"xxx.txt is not exist"); if( [filemanager createfileatpath:filepath contents:nil attributes:nil]) //创建文件 { // } } else { // } //数据写入文件 nsstring *buf=@"数据"; [buf writetofile:filepath atomically:yes encoding:nsutf8stringencoding error:nil]; //从文件读数据 nsstring * buf = [nsstring stringwithcontentsoffile:filepath encoding:nsutf8stringencoding error:nil];
下一篇: php SQL之where语句生成器