I want to read a large file in objective-c, and used in iphone development I used the follow code
NSData *data = [[NSData alloc] initWithContentsOfFile:file];
unsigned char *readData[2000];
[data getBytes:readData range:NSMakeRange(1000,3000)]
This maybe get the iphone app crash, because the size of the file is large.
I tried to use NSInputStream, but I can't find the range parameter in any method, can anyone give a help?
Thanks & Best Regards Timmy
Use NSFileHandle
: Seek to the offset where your data starts and start reading from there.
NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:filePath];
[fileHandle seekToFileOffset:1000];
NSData *data = [fileHandle readDataOfLength:2000];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.