I'm developing a file reader for a complex format. There are literally hundreds of different entries. In the way I'm doing it now I need to use two Streamreaders
because I need to extract some information before. These files are big enough to not read them at once.
What I want is to notify the user what lines have not been read. My structure is like this:
Streamreader file1 = new Streamreader(path);
while((line=file1.Readline()) != null)
{
if(line.StartsWith("HELLO")
{
//...
}
//... more conditions
}
Streamreader file2 = new Streamreader(path);
while((line=file2.Readline()) != null)
{
if(line.StartsWith("GOOD MORNING")
{
//...
}
//...more conditions
}
So if my reader was perfect at the end all lines are read. As things can be bizarre some entries can be not yet implemented, and I want to catch that lines. The problem here, as you see, is having two StreamReaders
.
My options are:
- Store in a array all not read lines and then use it for the second reading, subtracting line by line after reading it. Not good because I will be storing several thousand of lines there.
- Add all conditions in the second StreamReader to the first (all added) so this way I will know what lines are going to be read the second time. Better than previous but I need to modify my code in several places to make it run properly. I mean, when I wanted to implement the reading a new entry (second
StreamReader
) I will need to modify the firstStreamReader
too.
Is there any suggestion or any better way of doing this?