Want to achieve line-by-line reading from the last line to the first line of the txt file. Assuming there are 500 lines of data, each line needs to read about 200 characters, and the contents of txt file cannot be modified. Is it feasible to copy a string array line by line and then traverse the array in reverse order? There are other ways to welcome exchanges, just provide ideas.
The more convenient method is to read all the lines and then process them in reverse order, which wastes memory.
You can also move the file stream pointer to the end first and then use the
*seekSeries functions move the pointer forward to find line breaks, but this is inefficient
Another approach is to map files directly to memory.
linuxThe words are
mmapCan be used,
winI don’t know, it is much more efficient to find new line characters in reverse order than the above one.