<span style= "FONT-SIZE:14PX;" >nsdata *condata = responseobject;//set encoding format, this encoding format can read Chinese nsstringencoding enc = cfstringconvertencodingtonsstringencoding ( kcfstringencodinggb_18030_2000); nsstring *rcontent = [[NSString alloc]initWithData:condata encoding:enc]; nslog (@ "suceess %@", rcontent); nsstring * Filepath=[nshomedirectory () stringbyappendingformat:@ "/documents/%@", [durl lastpathcomponent]];// Output file full path, including file name nslog (@ "filepath %@", filepath); nsdata *incontent=[rcontent datausingencoding: Nsutf8stringencoding]; nslog (@ "ndata %@", incontent);// Determine if a file exists if ([[Nsfilemanager defaultmanager]fileexistsatpath:filepath]) { nslog (@ "Yes or no"); Delete Files [[NSFileManager defaultmanager] removeitematpath:filepath error:nil]; Want to file write content [[NSFileManager defaultmanager] createfileatpath:filepath contents:incontent attributes:nil]; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;}//1, get Documents folder path nsarray *paths=nssearchpathfordirectoriesindomains (Nsdocumentdirectory, nsuserdomainmask, yes); nslog (@ "paths %@", Paths); nsfilemanager *fm=[nsfilemanager defaultmanager]; nsarray *file=[fm subpathsofdirectoryatpath:[paths objectatindex:0] error:nil]; &NBSP;&NBSP;NSSTRING&NBSP;*DF=[PATHS&NBSP;OBJECTATINDEX:0];//2, get Documents folder path nslog (@ "sd %@", DF); if (!DF) { NSLog (@ "NOT&NBSP;FD"); } else { nslog (@ "FD"); } NSString *filenam=[[paths objectAtIndex:0] stringbyappendingpathcomponent:@ "1.txt"];//output documentThe full path of the 1.txt file under the S folder nslog (@ "filennn %@", Filenam); //Check the Documents folder for the presence of 1.txt files if ([[Nsfilemanager defaultmanager] fileexistsatpath:filenam]) { nslog (@ "Find"); }//read the contents of the 1.txt file under the Documents folder NSData *read=[nsdata datawithcontentsoffile:filenam]; NSString *ss=[[NSString alloc] initWithData:read encoding:NSUTF8StringEncoding]; NSLog (@ "ss",%@ ", SS);</span>
iOS file operations