My code replaces text instead of inserting it starting from 5 symbol:
NSFileHandle *file = [NSFileHandle fileHandleForUpdatingAtPath: filePath];
[file seekToFileOffset: 5];
[file writeData: [value dataUsingEncoding:NSUTF8StringEncoding]];
Is there any way to insert data to text file?
That's because your code set the index
position to 5and start writing from there, thus replacing everything from5onwards.I would copy the content of the file to a variable and modify it from there as a
string. as by the looks of it what you attempt to do is not possibleUpdate: Given that what you need is to write from X offset this should do the trick