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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to read strings with BufferedStream Class

Thread ID:





291 May 23,2002 08:55 AM UTC May 23,2002 09:51 AM UTC WinForms 1
Tags: FAQ
Mukesh Motwani
Asked On May 23, 2002 08:55 AM UTC

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 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


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon