c# - understanding streamreader and internalbuffer? -
i have .txt file has 3 lines following:
a50
b25
c25
this code:
filestream fs = new filestream(@"e:\1.txt", filemode.open); streamreader sr = new streamreader(fs); textbox1.appendtext(sr.readline() + "\r\n"); textbox1.appendtext(fs.position.tostring());
now after running above code,the output be:
a50
14
my question why position value 14? why it's not 4 pointer of stream point '\n' character @ end of first line a50?is related internalbuffer?and what's internalbuffer in detail , how work streamreader?
sorry bad english.
my question why position value 14?
the streamreader
has "overread" in order perform relatively few read operations on underlying stream. yes, it's related internal buffer - idea perform "chunky" read operations on underlying stream, reading more strictly needs in order satisfy current operation - preventing lots of single-byte reads.
to read line @ time no risk of over-reading, have read single byte @ time - might not single character. depending on stream implementation, may inefficient. instead, reads buffer hidden implementation detail (you don't have direct access buffer) , satisfies requests buffer until has read stream again.
Comments
Post a Comment