I have a text file which has content similar to one shown below. I used to a StremReader to read the header and then read the ASCII content. For some reason, it doesnt read till the end of the stream and returns -1. ReadLine also returns null. The problem is worse if the ascii content exceeds the default buffer size of 4096. I figured that using a BufferedStream would help since it caches the data and it indeed reads the whole ascii content which the streamreader couldnt. My problem is how to read the header with BufferedStream class since i couldnt find a member function which could return a string and then I could parse it to read the header.
8 8
255
kS`j`ktR^Q_‰ŸabR]Sa‡ž tv_Pgb’|Z€_\^l}^h}^jbWvVt’dbnHu^q€lNhOm“qY
/* C# code */
FileStream fs=new FileStream(fname,
FileMode.Open, FileAccess.Read);
//Open the file
StreamReader sr = new StreamReader(fs);
ReadHeader();//uses streamreader class
//Read the Ascii content
/* Doesnt work
while(sr.Peek() > -1)
{
buf[j]=sr.Read();
j++;
} */
/* Doesnt work either
for(j=0;j
MM
Mukesh Motwani
May 23, 2002 09:51 AM UTC
Pass the BufferedStream instead of the FileStream to the StreamReader.
BufferedStream bs=new BufferedStream(fs);
StreamReader sr = new StreamReader(bs);
Read the header using StreadReader and use the offset so that you can use BuffereStream bs.Read(offset,buf,buffersize);
Hope this helps others who had a similar problem.
Mukesh