Object-C file appending Method

Source: Internet
Author: User

Seektoendoffile

Attaches the content of a file to another file. Open another file for writing, locate the end of the file, and write the content of the first file to the second file.

CodeAs follows:

 # import 
  
    int main (INT argc, const char * argv []) {@ autoreleasepool {nsfilehandle * infile, * OUTFILE; nsdata * buffer; // open filea to read the infile = [nsfilehandle filehandleforreadingatpath: @ "filea.txt"]; If (infile = nil) {nslog (@ "open of filea.txt reading failed "); return 1;} // open fileb to update the operation OUTFILE = [nsfilehandle filehandleforwritingatpath: @ "fileb.txt"]; If (OUTFILE = nil) {nslog (@ "open of fileb for writing failed"); return 2;} // locate and locate the end of OUTFILE (append the file here) [OUTFILE seektoendoffile]; // read the infile and write its content to the OUTFILE buffer = [infile readdatatoendoffile]; [OUTFILE writedata: Buffer]; // close the read/write file [infile closefile]; [OUTFILE closefile];} return 0 ;}
  

After the search operation is completed, seektoendoffile returns the offset of the current file. Ignore this value. You can use this information to obtainProgramFile Size in


Address: http://blog.csdn.net/enuola/article/details/7797353

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.