NSString *home = NSHomeDirectory();//获取沙盒路径
//拼接Documents路径
//NSString *docPath = [home stringByAppendingStringt:@"/Documents"];
NSString *docPath = [home stringByAppendingPathComponent:@"Documents"];
NSString *filePath = [docPath stringByAppendingPathComponent:@"data.plist"];
NSArray *array = @[@1,@2,@"123"];
//只有具备writeToFile的对象才能使用plist存储,NSArray
[array writeToFile:filePath atomically:YES];
主要是获取路径,然后把文件写到这个路径里就好了
NSString *filePath =[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/newfile.txt"];
NSString *testString = @"文件内容";
[testString writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];