How to deal with a very large text file?

前端 未结 7 2051
鱼传尺愫
鱼传尺愫 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:39

    If you had fixed width lines then using a RandomAccessFile might solve a lot of your problems. I realise that your lines are probably not fixed width, but you could artificially impose this by adding an end of line indicator and then padding lines (eg with spaces).

    This obviously works best if your file currently has a fairly uniform distribution of line lengths and doesn't have some lines that are very, very long. The downside is that this will artificially increase the size of your file.

提交回复
热议问题