NSString的导出

字符串的导出,写到某个文件中去

void stringExport(){

NSString *str=@"123456";

//if file not exist will not show error and it will create

//if file folder not exist will show error文件夹不存在

//if encoding not match will show error编码指定错误

NSString *path=@"/User/apple/Desktop/test.txt";

NSError *error;

//Will cover old content.

//atomically原子性。safer,123/456 if error temp will be delete and Text.txt will not be created

//

// 非原子性 only 123

//

[str writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error];

if(error){

NSLog(@"Failed, infor%@",[error localizedDescription]);//return main error infor

}else{

NSLog(@"Successful");

}

}

原文地址:https://www.cnblogs.com/yesihoang/p/4506006.html