C
Chris B
I get a corrupted line using ReadLine after using the Seek method.
I have easily rewritten it to not use the Seek call, but this kind of event
is worrying.
(Yes I know reading the file twice is not very smart, but the code is
designed to only run
a few times and this section is non critical -- using this solution appeared
to be the simplest
and less error prone )
System.IO.StreamReader srReadLine = new System.IO.StreamReader(
(System.IO.Stream)System.IO.File.OpenRead(fileInfo.FullName),System.Text.Enc
oding.ASCII);
srReadLine.BaseStream.Seek(0,System.IO.SeekOrigin.Begin); //This seek is OK
// Look for some record buried in the file
while (srReadLine.Peek() > -1)
{
// find some record, if found then break else throw exception.
row = srReadLine.ReadLine();
}
srReadLine.BaseStream.Seek(0,System.IO.SeekOrigin.Begin); //This seek leads
to the ReadLine corrupting
while (srReadLine.Peek() > -1)
{
//If the Seek above is used then the ReadLine will be corrupted as the
Stream gets neaar the end of the file
// Reads about 50 lines OK. Then 5 lines from the end ReadLine returns half
of that line
// and most of the final line in that file!!!!!!
row = srReadLine.ReadLine();
}
I have easily rewritten it to not use the Seek call, but this kind of event
is worrying.
(Yes I know reading the file twice is not very smart, but the code is
designed to only run
a few times and this section is non critical -- using this solution appeared
to be the simplest
and less error prone )
System.IO.StreamReader srReadLine = new System.IO.StreamReader(
(System.IO.Stream)System.IO.File.OpenRead(fileInfo.FullName),System.Text.Enc
oding.ASCII);
srReadLine.BaseStream.Seek(0,System.IO.SeekOrigin.Begin); //This seek is OK
// Look for some record buried in the file
while (srReadLine.Peek() > -1)
{
// find some record, if found then break else throw exception.
row = srReadLine.ReadLine();
}
srReadLine.BaseStream.Seek(0,System.IO.SeekOrigin.Begin); //This seek leads
to the ReadLine corrupting
while (srReadLine.Peek() > -1)
{
//If the Seek above is used then the ReadLine will be corrupted as the
Stream gets neaar the end of the file
// Reads about 50 lines OK. Then 5 lines from the end ReadLine returns half
of that line
// and most of the final line in that file!!!!!!
row = srReadLine.ReadLine();
}