The first step
Step two, add the code
1 //Write File2-(void) Writeoxy_rawdata: (NSString *) Datastr;3 {4NSDate * senddate=[NSDate Date];5NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];6[Dateformatter Setdateformat:@"YYYY-MM-DD Hh-mm-ss"];7NSString * locationstring=[Dateformatter stringfromdate:senddate];8NSLog (@"locationstring:%@", locationstring);9Nsarray *documentpaths =nssearchpathfordirectoriesindomains (NSDocumentDirectory, nsuserdomainmask,yes);Ten //Use the C function nssearchpathfordirectoriesindomains to get the full path of the directory in the sandbox. The function has three parameters, a directory type, a he domain mask, and a Boolean value. Where the Boolean value indicates whether the path needs to be extended through the ~. And the first parameter is constant, which is nssearchpathdirectory. In iOS, the latter two parameters are the same: Nsuserdomainmask and YES. OneNSString *ourdocumentpath =[documentpaths Objectatindex:0]; A //Step two: Generate files under this path: -NSString *filename=[ourdocumentpath stringbyappendingpathcomponent:[nsstring stringWithFormat:@"%@.txt", locationstring]]; - //FileName is the file name of the saved files the //Step Three: Write data to the file: - [datastr writetofile:filename atomically:yes encoding:nsutf8stringencoding Error:nil]; - //writes the NSData type Object data to the file, the file name is filename, and the last: reads the data from the file: -}View Code
The third step, as in itunes
IOS fetching files from the real machine