Write operations for iOS implementation files

Source: Internet
Author: User

//

Main.m

nsfilehandledemo2-Write

//

Created by Guoyule on 15/2/19.

Copyright (c) 2015 Guoyule. All rights reserved.

//

This is a write file

#import <Foundation/Foundation.h>

#define PATH @ "/users/guoyule/desktop/guoyule.rtf"

int main (int argc, const char * argv[]) {

@autoreleasepool {

Insert code here ...

NSLog (@ "Hello, world!");

Write a file

Nsfilehandle * fh = [Nsfilehandle Filehandleforwritingatpath:path];

Open a file in a read-only manner, generating a file handle

In the file handle, it's written in the file.

NSData * data = [@ "Guoyule" datausingencoding:nsutf8stringencoding];

String to Data

Writing data to a file

[FH Seektoendoffile];

Navigate to the end of the file and start writing at the end of the file

You can also navigate to any location

[FH seektofileoffset:100000];//Note that the TXT will be automatically wrapped.

[FH Writedata:data];

Write one more time.

[FH Writedata:data];

Emptying source file data

[FH truncatefileatoffset:0];

Truncate the source data to the remaining number of bytes established

int i = 0;

while (i++ < 5) {

[FH Writedata:data];

}

Each time the data is written, the last write will continue to be written from scratch every time the file is opened.

}

NSLog (@ "Guoyule");

return 0;

}

Write operations for iOS implementation files

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.