Java Tutorial

Buffer Streams

Buffered streams are basically used to reduce physical number of read and write operation i.e., buffered streams always increases the performance of ordinary streams.

In byte streams we have two buffered streams, they are BufferedInputStream and BufferedOutputStream.

Buffered Input Stream:

BufferedInputStream class is used for reducing number of physical read operation. When we create an object of BufferedInputStream, we get a temporary peace of memory space whose default size is 1024 bytes and it can be increased by multiples of 2.

Constructors:

public BufferedInputStream (FileInputStream);

For example:

FileInputStream fis=new FileInputStream ("abc.dat");
BufferedInputStream bis=new BufferedInputStream (fis);

Buffered Output Stream:

BufferedOutputStream class is used for reducing number of physical write operation when we create an object of BufferedOutputStream, we get a temporary peace of memory space whose default size is 1024 bytes and it can be increased by multiple of 2.

Constructors:

public BufferedOutputStream (FileOutputStream);

For example:

FileOutputStream fos=new FileOutputStream ("abc.dat"); 
BufferedOutputStream bos=new BufferedOutputStream (fos);

Byte streams will transfer one byte of data and they will be implemented in system level applications such as flow of data in electronic circuits, development of ftp protocol etc.

Character streams are those in which 2 bytes of data will be transferred and it can be implemented in higher level applications such as internet applications, development of protocols etc., like http etc.