I’m trying to seek 1,000 bytes into a file handle and write it to an instance of NSData (or NSMutableData).
What am I doing wrong here?
int offset = 1000;
NSFileHandle *fHandle;
NSMutableData *data;
fHandle = [NSFileHandle fileHandleForReadingAtPath:@"bigtextfile.txt"];
[fHandle seekToFileOffset:offset];
data = [NSMutableData data];
[fHandle writeData:data];
[fHandle closeFile];
[data length]; // this comes out to 0 bytes?
I am not sure you trying to read data after seeking or want to write some thing there? — you are opening file for reading then you are trying to write empty data.
If you want to read then using following line or similar API’s not write
If you want to write then open the file for writing — then have some content in NSData object and write it to the file.