We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to read strings with BufferedStream Class

Thread ID:

Created:

Updated:

Platform:

Replies:

291 May 23,2002 04:55 AM May 23,2002 05:51 AM Windows Forms 1
loading
Tags: FAQ
Mukesh Motwani
Asked On May 23, 2002 04:55 AM

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

Mukesh Motwani
Replied On May 23, 2002 05:51 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;