I am trying to read a text file containing characters in billions. Using the function
contentOfFile is not working, as my application get crashed due to it.
So anybody please send me the sample code so that I get the chunks according to my requirement.Whichever i need i wanna get that one only.
please reply as soon as possible.
I’m guessing this is an iOS app. In that case, you are likely hitting the memory limit by calling
contentsOfFile:because that method is trying to read the entire contents of the file into a variable (memory). Remember that on iOS your app must play nice and if it decides to consume too much memory, then the watchdog process will kill your app to save the device from rebooting (which happens because there is no disk to swap to on iOS devices).Have you had a look at
NSFileHandle?NSFileHandlesupports seeking within a text a file. With some simple iteration you can use the following to methods to seek within the file and read chunks of data:It might look something like this. Assume
pathToFileis anNSStringcontaining the path to the text file to be read in.