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");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
r1is more efficient. TheInputStreamReaderitself doesn’t have a large buffer. TheBufferedReadercan be set to have a larger buffer thanInputStreamReader. TheInputStreamReaderinr2would 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.
Results at my Latitude E5500 with a Seagate Momentus 7200.3 harddisk: