Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: difference between fileReader and bufferReader

  1. #1
    Junior Member shadihrr's Avatar
    Join Date
    Jan 2010
    Location
    home
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default difference between fileReader and bufferReader

    hi all
    I try to understand what is the difference between fileReader and buffered reader i know that fileReader get hard disk and that makes the program slow but i can't figure it out so what bufferedReader do in order to make it fast???
    thanks
    shadi


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: difference between fileReader and bufferReader

    I only know what I read in the API doc. Have you read it?

    For example:
    Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient.

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: difference between fileReader and bufferReader

    A file reader can only read files. A buffered reader can read from pretty much any type of stream it can create a buffer for.

  4. #4
    Junior Member shadihrr's Avatar
    Join Date
    Jan 2010
    Location
    home
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: difference between fileReader and bufferReader

    A file reader can only read files. A buffered reader can read from pretty much any type of stream it can create a buffer for.
    I want to know about its affection on speed
    I only know what I read in the API doc. Have you read it?

    For example:
    Quote:
    Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient.
    I want to know what happened in hardware when you use bufferedReader(/Writer)

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: difference between fileReader and bufferReader

    A buffered reader will pre-emptively read in the stream and store it into a buffer in the memory (hence the name: buffered reader). A file reader will only read from the hard disk each time it's asked to, and only how much it's asked to (I think, there's likely a second alternative where the OS opens the file and stores it into a buffer, but the file reader must use JNI to access this data).

  6. The Following User Says Thank You to helloworld922 For This Useful Post:

    shadihrr (June 8th, 2010)

  7. #6
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: difference between fileReader and bufferReader

    As far as I'm aware I think you can pass a FileReader to a BufferedReader. The BufferedReader is just a wrapper reader with a more helpful interface to it then the other readers. At the end of the day the FileReader will just open an inputstream anyways which the BufferedReader will read.

    As long as you read from the filesystem you will always have some speed issues no matter if you use the buffered reader or the filereader, I dont think there is much difference in speed though.

    If you want speed, you need to load things into memory and do it that way

    // Json

  8. The Following User Says Thank You to Json For This Useful Post:

    shadihrr (June 8th, 2010)

  9. #7
    Junior Member shadihrr's Avatar
    Join Date
    Jan 2010
    Location
    home
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: difference between fileReader and bufferReader

    thanks to all your answer they were helpful!!

Similar Threads

  1. Need to know this difference
    By arvind in forum Java Theory & Questions
    Replies: 2
    Last Post: January 19th, 2010, 06:24 AM
  2. Difference between Vector and Arraylist
    By Lil_Aziz1 in forum Collections and Generics
    Replies: 4
    Last Post: January 3rd, 2010, 11:03 AM
  3. FileReader need assistance
    By tazjaime in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: November 8th, 2009, 01:12 AM
  4. Difference between Arraylist and Vector in abstractTableModel ?
    By riddhik84 in forum Collections and Generics
    Replies: 2
    Last Post: November 7th, 2009, 04:22 PM
  5. Difference between Speech API and Sound API
    By zeeshanmirza in forum Java SE APIs
    Replies: 1
    Last Post: October 22nd, 2009, 12:22 AM