iOS file operations

Source: Internet
Author: User

<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.