BufferedInputStream vs. InputStream

A

Andersen

What is the fundamental difference between BufferedInputStream and
InputStream?
 
O

Oliver Wong

Andersen said:
What is the fundamental difference between BufferedInputStream and
InputStream?

A BufferedInputStream adds functionality to another input
stream-namely, the ability to buffer the input and to support the mark and
reset methods. InputStream, meanwhile, is an abstract class is the
superclass of all classes representing an input stream of bytes.

BTW, I composed this "intelligent sounding" answer by copying and
pasting the first sentence of the JavaDocs for BufferedInputStream and the
first sentence of the JavaDocs for InputStream. You should try reading more
about those two if you haven't already.

- Oliver
 
R

Rationem

The difference, as you may have guessed, is that BufferedInputStream
uses a buffer. BufferedInputStream is also almost always faster than
regular InputStream implementations because a bufferedStream does not
neet to as many asyncronous reads.
 
S

Steve Horsley

Andersen said:
What is the fundamental difference between BufferedInputStream and
InputStream?

An InputStream has to make an operating system call every time
you call its read() method. This can be very inefficient in terms
of cpu usage. A BufferedInputStream can call the operating system
just once and collect a whole array of bytes, and then service
many read() calls from its local buffer before going back to the
operating system for more. This can improve performance by a
factor of 10 or more.

Steve
 
R

Roedy Green

Since when?

oops. I should have said BufferedReader adds readLine to a Reader.

In the days before Readers could you not say

System.in.readLine() ??? If not, how DID you read lines from the
console?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top