Quickly replace first line of large file

前端 未结 2 866
孤独总比滥情好
孤独总比滥情好 2021-02-19 18:02

I have many large csv files (1-10 gb each) which I\'m importing into databases. For each file, I need to replace the 1st line so I can format the headers to be the column names.

2条回答
  •  不知归路
    2021-02-19 18:49

    If you can guarantee that fixedLine is the same length (or less) as line, you can update the files in-place instead of copying them.

    If not, you can possibly get a little performance improvement by accessing the .BaseStream of your StreamReader and StreamWriter and doing big block copies (using, say, a 32K byte buffer) to do the copying, which will at least eliminate the time spent checking every character to see if it's an end-of-line character as happens now with reader.ReadLine().

提交回复
热议问题