I’m tasked with reading a large text files(not XML’s) may be in GB’s in size. I need to split the file into smaller chunks by checking for the header . Suggest me some method to achieve this. Sample text structure will be
Sample large file
header_start
blaw
blaw
blawasasdasda
header_start
blaw
blawasdasda
blaw
Need to split into
1.txt
header_start
blaw
blaw
blawasasdasda
2.txt
header_start
blaw
blawasdasda
blaw
Please help me to achieve this in .net 4.0 with less time
Thanks
Vivek
Create a
StreamReaderfor the large file and callReadLine()in a loop.Maintain a
StreamWriterfor the current output file.For each line, check whether it’s a header, and, if it is, open a new target file in the
StreamWriter. If it isn’t, just write that line to the currentStreamWriter.