Raymond Mallari
Raymond Mallari

Reputation: 23

The use of BufferedInputStream

What does BufferedInputStream do in a program. I'm currently learning to download images from the internet using java, all of the tutorial I've been through was using this and every single one doesn't explain to me the usage of this function.

Upvotes: 1

Views: 51

Answers (1)

Adya
Adya

Reputation: 1112

The Java BufferedInputStream class, java.io.BufferedInputStream, provides reading of chunks of bytes and buffering for a Java InputStream, including any subclasses of InputStream. Reading larger chunks of bytes and buffering them can speed up IO quite a bit.

Rather than read one byte at a time from the network or disk, the BufferedInputStream reads a larger block at a time into an internal buffer. When you read a byte from the Java BufferedInputStream you are therefore reading it from its internal buffer. When the buffer is fully read, the BufferedInputStream reads another larger block of data into the buffer.

This is typically much faster than reading a single byte at a time from an InputStream, especially for disk access and larger data amounts.

Upvotes: 6

Related Questions