WriteToFile and Nsfilehandle

Source: Internet
Author: User

 [Writer Writetofile:logpath atomically:YESThis is written in a file, and it's all covered-up.

atomically Yes or No:yes indicates that the file is written atomically, which means that a temporary file is created until the file content is successfully imported into the target file.
NO is written directly into the target file.


If you want to use an append file write, that is, the contents of the original file is not overwritten can be used Nsfilehandle:

1 #import2 intMainintargcConst Char*argv[])3 {4 @autoreleasepool {5 6Nsfilehandle *infile, *OutFile;7 8NSData *buffer;9 Ten  One  A         //Open Filea for read operations -  -InFile =[Nsfilehandle FILEHANDLEFORREADINGATP the  -         if(InFile = =Nil) -  -         { +  -NSLog (@"Open of FileA.txt reading failed") +  A             return 1; at  -         } -  -  -  -        //Open Fileb for update operation in  -OutFile = [Nsfilehandle filehandleforwritingatpath:@"FileB.txt"]; to  +        if(OutFile = =Nil) -  the        { *  $NSLog (@"Open of Fileb for writing failed")Panax Notoginseng  -            return  2; the  +        } A  the  +  -        //Locate and navigate to the end of the outfile (append file after this) $  $ [OutFile seektoendoffile]; -  -  the  -       //read infile and write its contents to outfileWuyi  theBuffer =[InFile readdatatoendoffile]; -  Wu [OutFile Writedata:buffer]; -  About   $         //close Read and write files -  - [InFile CloseFile]; -  A [OutFile CloseFile]; +  the      } -  $     return 0; the  the}


Seektoendoffile returns the offset of the current file after the search operation has finished executing. Choose to ignore this value and, if necessary, use this information to get the file size in your program

WriteToFile and Nsfilehandle

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.