我想保存一些历史记录并将其加载到文本文件中
我使用此代码
- (void) saveHistory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"file.txt"];
[resultWindow.text writeToFile:filePath atomically:TRUE encoding:NSUTF8StringEncoding error:NULL];
}
- (void) loadHistory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"file.txt"];
if (resultWindow.text == nil) {
resultText = @"";
resultWindow.text = resultText;
}
resultWindow.text = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
}
文件保存好!但是当我加载resultWindow.text
为空时(0x00000000)