How to write super-fast file-streaming code in C#?

后端 未结 9 1914
遥遥无期
遥遥无期 2020-11-28 19:11

I have to split a huge file into many smaller files. Each of the destination files is defined by an offset and length as the number of bytes. I\'m using the following code:<

9条回答
  •  盖世英雄少女心
    2020-11-28 20:01

    Using FileStream + StreamWriter I know it's possible to create massive files in little time (less than 1 min 30 seconds). I generate three files totaling 700+ megabytes from one file using that technique.

    Your primary problem with the code you're using is that you are opening a file every time. That is creating file I/O overhead.

    If you knew the names of the files you would be generating ahead of time, you could extract the File.OpenWrite into a separate method; it will increase the speed. Without seeing the code that determines how you are splitting the files, I don't think you can get much faster.

提交回复
热议问题