I've been doing some research on File I/O and have been introduced to the BufferedReader class and the FileReader class. I'm just wondering when and why to use one over the other. What is the difference(s) between the two?
Thanks
5 Replies - 4683 Views - Last Post: 27 October 2010 - 05:01 PM
#1
differences between BufferedReader and FileReader
Posted 27 October 2010 - 04:20 PM
Replies To: differences between BufferedReader and FileReader
#2
Re: differences between BufferedReader and FileReader
Posted 27 October 2010 - 04:31 PM
A FileReader class is a general tool to read in characters from a File. The BufferedReader class can wrap around Readers, like FileReader, to buffer the input and improve efficiency. So you wouldn't use one over the other, but both at the same time by passing the FileReader object to the BufferedReader constructor.
#3
Re: differences between BufferedReader and FileReader
Posted 27 October 2010 - 04:43 PM
Thanks for the reply macosxnerd. That helps alot. What exactly do you mean by "buffer the input"?
#4
Re: differences between BufferedReader and FileReader
Posted 27 October 2010 - 04:44 PM
Rather than read the input, than pass off each individual byte or character, the input is stored until the buffer's capacity is hit, then it is returned. BufferedReader handles all of this internally.
#5
Re: differences between BufferedReader and FileReader
Posted 27 October 2010 - 04:54 PM
Oh ok, so the buffer is sort of like a holding area for the data? I guess this increases performance by sending a large piece of the data rather than trying to send individual characters one at a time?
Btw, macosxnerd, how did you learn about this lower level stuff and what goes on "behind the scenes"? I'm really interested in this sort of thing, but unfortunately, the books I own and have looked through don't cover any of this.
Btw, macosxnerd, how did you learn about this lower level stuff and what goes on "behind the scenes"? I'm really interested in this sort of thing, but unfortunately, the books I own and have looked through don't cover any of this.
#6
Re: differences between BufferedReader and FileReader
Posted 27 October 2010 - 05:01 PM
It's outlined in the Java documentation, if you look at the FileReader and BufferedReader classes online.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote







|