gjs368
November 26th, 2002, 09:38 AM
I have a random-access text file that I need to be able to navigate through by a defined number of characters in order to pull out individual records. I am using Stream.Seek to position the file pointer to the proper place, and I can tell by checking Stream.Position that the pointer does indeed appear to move to the requested location. However, StreamReader.Read() always picks up the very next character after the last character read in the last iteration :confused:
Even stranger: I have some header information that I want to skip past (FILEHDR_STRLEN) and the buffer always gets the proper information on the first read. :confused: :confused:
Here is the code in question:
StreamReader srRead = new StreamReader((System.IO.Stream)File.OpenRead(strFilename), System.Text.Encoding.ASCII);
int nIter = 0;
char[] buffer =new char[10];
while (srRead.BaseStream.Position < srRead.BaseStream.Length)
{
srRead.BaseStream.Position = 0;
srRead.BaseStream.Seek((FILEHDR_STRLEN + (SITEINFO_STRLEN * nIter)), SeekOrigin.Begin);
srRead.Read(buffer, 0, 10);
nIter++;
}
srRead.DiscardBufferedData();
srRead.Close();
I have tried various forms of this block, but always get the same result.
Any Ideas?
Even stranger: I have some header information that I want to skip past (FILEHDR_STRLEN) and the buffer always gets the proper information on the first read. :confused: :confused:
Here is the code in question:
StreamReader srRead = new StreamReader((System.IO.Stream)File.OpenRead(strFilename), System.Text.Encoding.ASCII);
int nIter = 0;
char[] buffer =new char[10];
while (srRead.BaseStream.Position < srRead.BaseStream.Length)
{
srRead.BaseStream.Position = 0;
srRead.BaseStream.Seek((FILEHDR_STRLEN + (SITEINFO_STRLEN * nIter)), SeekOrigin.Begin);
srRead.Read(buffer, 0, 10);
nIter++;
}
srRead.DiscardBufferedData();
srRead.Close();
I have tried various forms of this block, but always get the same result.
Any Ideas?