Buffered Streams in Java Scanning and Formatting

Introduction

As we have seen earlier about  streams in Java and Byte Streams , Character Streams in our previous lessons , we are going to discuss about   Buffered Streams in Java.

What is Buffered Stream

A buffer is a shared area which can be accessible by hardware devices and program processes.This allows each device or process to work with out lock.We can say a buffer as middle point like cache to support the co-ordination of activities.
A Buffered stream is a stream which reads / writes data from the buffer ( earlier streams depends on O.S to read write operations ) . The stream uses the O.S support only when there is a empty buffer.This is same for the output streams also.O.S support is used when only buffer is full.
Programs can convert non-buffered streams to buffered streams with generic constructors as seen below.

InputStreamReader instrt = new BufferedReader(new FileReader("abc.txt"));
OutputStreamReader outstrt = new BufferedWriter(new FileWriter("out.txt"));

BufferedStream Classes are

  • BufferedInputStream
  • BufferedOutputStream
  • BufferedReader
  • BufferedWriter

Buffer Flushing :

We can clear the buffer , without waiting it to full.This is known as flushing. Auto flush is available some buffer output classes.

Flushing can be done manually by invoking flush()  method .

Does euphonious remind you of an attachment

Previous                                                                                                                                            Next

0 comments:

Post a Comment