//
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