//document content
NSString *content = @"aShen. All rights rese";
//file path
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"jsdfhj.text"];
// atomically :YES first store the content of the written file in a temporary file, if successful, it will overwrite the source file, NO directly delete the content of the file and write the new content directly
BOOL isWrit = [content writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
if (isWrit) {
NSLog( @"Write successful");
}else{
NSLog( @"Write failed");
}