How to deal with a very large text file?

前端 未结 7 2053
鱼传尺愫
鱼传尺愫 2021-02-07 14:40

I\'m currently writing something that needs to handle very large text files (a few GiB at least). What\'s needed here (and this is fixed) is:

  • CSV-based, following
7条回答
  •  被撕碎了的回忆
    2021-02-07 15:32

    • Finding the start of line:

    Stick with UTF-8 and \n denoting the end of the line should not be a problem. Alternatively you can allow UTF-16, and recognize the data: it has to be quoted (for instance), has N commans (semicolons) and another end of line. Can read the header to know how many columns the structure.

    • Inserting into the middle of the file

    can be achieved by reserving some space at the end/beginning of each line.

    • appending lines at the end

    That's trivial as long as the file is locked (as any other modifications)

提交回复
热议问题