Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 987645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:30:45+00:00 2026-05-16T05:30:45+00:00

What are the differences (if any) between the following two buffering approaches? Reader r1

  • 0

What are the differences (if any) between the following two buffering approaches?

Reader r1 = new BufferedReader(new InputStreamReader(in, "UTF-8"), bufferSize);
Reader r2 = new InputStreamReader(new BufferedInputStream(in, bufferSize), "UTF-8");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:30:45+00:00Added an answer on May 16, 2026 at 5:30 am

    r1 is more efficient. The InputStreamReader itself doesn’t have a large buffer. The BufferedReader can be set to have a larger buffer than InputStreamReader. The InputStreamReader in r2 would act as a bottleneck.

    In a nut: you should read the data through a funnel, not through a bottle.


    Update: here’s a little benchmark program, just copy’n’paste’n’run it. You don’t need to prepare files.

    package com.stackoverflow.q3459127;
    
    import java.io.BufferedInputStream;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.Reader;
    
    public class Test {
    
        public static void main(String... args) throws Exception {
    
            // Init.
            int bufferSize = 10240; // 10KB.
            int fileSize = 100 * 1024 * 1024; // 100MB.
            File file = new File("/temp.txt");
    
            // Create file (it's also a good JVM warmup).
            System.out.print("Creating file .. ");
            BufferedWriter writer = null;
            try {
                writer = new BufferedWriter(new FileWriter(file));
                for (int i = 0; i < fileSize; i++) {
                    writer.write("0");
                }
                System.out.printf("finished, file size: %d MB.%n", file.length() / 1024 / 1024);
            } finally {
                if (writer != null) try { writer.close(); } catch (IOException ignore) {}
            }
    
            // Read through funnel.
            System.out.print("Reading through funnel .. ");
            Reader r1 = null;        
            try {
                r1 = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"), bufferSize);
                long st = System.nanoTime();
                for (int data; (data = r1.read()) > -1;);
                long et = System.nanoTime();
                System.out.printf("finished in %d ms.%n", (et - st) / 1000000);
            } finally {
                if (r1 != null) try { r1.close(); } catch (IOException ignore) {}
            }
    
            // Read through bottle.
            System.out.print("Reading through bottle .. ");
            Reader r2 = null;        
            try {
                r2 = new InputStreamReader(new BufferedInputStream(new FileInputStream(file), bufferSize), "UTF-8");
                long st = System.nanoTime();
                for (int data; (data = r2.read()) > -1;);
                long et = System.nanoTime();
                System.out.printf("finished in %d ms.%n", (et - st) / 1000000);
            } finally {
                if (r2 != null) try { r2.close(); } catch (IOException ignore) {}
            }
    
            // Cleanup.
            if (!file.delete()) System.err.printf("Oops, failed to delete %s. Cleanup yourself.%n", file.getAbsolutePath());
        }
    
    }
    

    Results at my Latitude E5500 with a Seagate Momentus 7200.3 harddisk:

    Creating file .. finished, file size: 99 MB.
    Reading through funnel .. finished in 1593 ms.
    Reading through bottle .. finished in 7760 ms.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.