#import <Foundation/Foundation.h> //写入文件 int main(int argc, const char * argv[]) { @autoreleasepool { NSString * str = @"你是一仅仅小狗 "; //创建路径 NSString * path =@"/Users/ms/Desktop/hello/my.txt"; NSError * error; //第一个參数给出路径 //atomically:YES BOOL isWriteSucess = [str writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error]; if(isWriteSucess) { NSLog(@"写入成功"); } else { NSLog(@"写入失败"); } //NSLog(@"%@",error); } return 0; }