I am using the following code to write in a file.
fileName = [[NSBundle mainBundle] pathForResource: @"user" ofType: @"txt"];
NSFileHandle *myHandle = [NSFileHandle fileHandleForUpdatingAtPath:fileName];
[myHandle seekToEndOfFile];
NSData *dataName = [uname dataUsingEncoding: NSUnicodeStringEncoding];
if ([dataName writeToFile:fileName atomically:YES])
NSLog(@"writeok");
[myHandle seekToEndOfFile];
It overwrites the file. Suppose the file already contains the string "box". Now when I write a new word, "Hello", then the file contains only "Hello", not "box".
What is the problem with the code?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…