473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Streamreader - Can I avoid buffering?

Hi.
I am tring to read from random parts of an SDF file using a stream
reader. I know each line in my file is 30 chars long so I know where in
the file I want to go to read a specific record.
The first seek works fine. But due to buffering (from what I've read)
the second seek will not point to the start of the file and will be
positioned just 30 bytes after the first seek. Is there any way I can
avoid the buffering or is there another solution that would allow me to
read from any part of a text file?

Any help/advice would be great.
My code.

Dim bytes(29) As Char
Dim bytes2(29) As Char

Dim fs As New FileStream("h:\address_procV1\names.sdf", fileMode.Open,
FileAccess.Read)
' Create a character reader.
Dim sr As New StreamReader(fs)
sr.BaseStream.Seek(21657360, SeekOrigin.Begin)
'''sr.ReadBlock(bytes2, 0, 30)
sr.Read(bytes, 0, 30)
sr.BaseStream.Seek(0, SeekOrigin.Begin)
'''sr.ReadBlock(bytes2, 0, 30)
sr.Read(bytes2, 0, 30)
Nov 21 '05 #1
2 1714
You can call the .DiscardBufferedData method of the StreamReader before
you next seek and that should work.

Nov 21 '05 #2
Chris Dunaway wrote:
You can call the .DiscardBufferedData method of the StreamReader before
you next seek and that should work.


Thanks a million Chris. Works as I want now.
Spent so long looking at it I didn't even notice the .DiscardBufferedData
Cheers
Dave
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: oafyuf | last post by:
Hi, I'm having performanbce issues with StreamReader and was wondering what I could do to improve it... The following takes around 3 seconds to process! The content of the response is: ...
5
by: Anders Olsson | last post by:
I need to create a StreamReader which starts from the position of an existing StreamReader. This way, the second StreamReader can read lines "ahead" in an own loop, and then I can go back to the...
4
by: IDandT | last post by:
Hi, I am writing a small program that connect to IRC. I create a TCPClient connection and i use stream to read and write data. It works ok, but i have a problem reading from stream. ...
3
by: Arno | last post by:
Hi, I'm using TcpClient for communication between two PC running a small piece of software. The protocol used has been designed internally and is HTTP similar (command line, headers, body). A...
2
by: Joan Reddy | last post by:
Can anyone tell me why this code doesn't work for setting the pointer to the begining of a file stream? This is driving me crazy. At the end of Main1, sString2 is the second line of the file, as...
4
by: Chris S. | last post by:
I'm curious - does StreamReader.ReadToEnd() handle chunk loading of data or does it block until the whole stream is loaded? I've been use to handling the buffer myself but I'm thinking maybe this...
9
by: lord.zoltar | last post by:
Hi, I'm having some trouble with a StreamReader. I use a System.IO.StreamReader to read a text file and then print it. If the user has selected a range of pages starting past the first page, I...
9
by: Matt Bailey | last post by:
I am writing an ASP page with a C# backend. This page uses a StreamReader to input a file and pull out a specific section of the text based on markers inside. While the code I have works, I get a...
4
by: somequestion | last post by:
Question 1. i am using StreamReader Class like this... string str = string.Empty; StreamReader sr = new StreamReader(fsIn,Encoding.Default) while ((str = sr.ReadLine()) != null) { // wanna get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.