r/javahelp • u/tnelson12179 • Feb 13 '20
What the freak are buffered readers?
Can someone help me and tell me what exactly it does? Thanks
16
Upvotes
r/javahelp • u/tnelson12179 • Feb 13 '20
Can someone help me and tell me what exactly it does? Thanks
23
u/Northeastpaw Feb 13 '20
A non-buffered reader will read one byte at a time from the underlying source. Depending on the source reading byte-by-byte is really slow.
To improve performance a buffered reader will read some amount of bytes into memory during the first read for one byte. Subsequent reads will read from this buffer until the buffer is empty. Then the reader will grab more data from the underlying source and put it into the buffer. This can drastically improve read performance at the cost of additional memory usage.