5 Replies - 7418 Views - Last Post: 27 October 2010 - 05:01 PM Rate Topic: -----

#1 Codebug  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 244
  • Joined: 11-October 09

differences between BufferedReader and FileReader

Posted 27 October 2010 - 04:20 PM

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
Is This A Good Question/Topic? 0
  • +

Replies To: differences between BufferedReader and FileReader

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10568
  • View blog
  • Posts: 39,131
  • Joined: 27-December 08

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.
Was This Post Helpful? 1
  • +
  • -

#3 Codebug  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 244
  • Joined: 11-October 09

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"?
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10568
  • View blog
  • Posts: 39,131
  • Joined: 27-December 08

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.
Was This Post Helpful? 0
  • +
  • -

#5 Codebug  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 244
  • Joined: 11-October 09

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.
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10568
  • View blog
  • Posts: 39,131
  • Joined: 27-December 08

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. :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1