General approach #2: Read the entire file, store position of lines
With this approach, you also read through the entire file once, but
instead of storing the entire file (all the text) in memory, you only
store the binary positions inside the file where each line started.
You can store these positions in a similar data structure as the one
storing the lines in the first approach.
Whever you want to read line X, you have to re-read the line from the
file, starting at the position you stored for the start of that line.
Pros: Almost as easy to implement as the first approach Cons: can take a while to read large files