可能重复:
objective C: write in a csv (txt) string contained in some textfield
我有这个代码在csv文件(txt)中写一个字符串(要写的字符串是:csvString)
NSString *resourceFileName = @"Client";
NSString *pathToFile =[[NSBundle mainBundle] pathForResource: resourceFileName ofType: @"txt"];
NSError *error;
NSString *fileString = [NSString stringWithContentsOfFile:pathToFile encoding:NSUTF8StringEncoding error:&error];
if (!fileString) {
NSLog(@"Error reading file.");
}
[csvString writeToFile:pathToFile atomically:YES encoding:NSUTF8StringEncoding error:nil];
但它不起作用,为什么?