Menu
Topics Index
...
`


Input/Output: Exploring java.io > Byte Streams >
Siva Nookala - 20 Feb 2017
All the InputStreams and OutputStreams we have seen so for use unbuffered Streams. This means each read or write request is directly handled by the underlying Operating System. This will reduce the program efficiency. To reduce this kind of overhead, Java implements buffered I/O streams. Buffered input streams read data from a memory area known as buffer. We send request to OS only when the buffer is empty. Similarly, buffered output streams write data to a buffer, and request are send to OS only when the buffer is full and there is no space further to perform write operation.

We convert the unbuffered stream into buffered stream by wrapping to a buffered stream. Here's how we do it.
inputStream = new BufferedReader(new FileReader("fileOne.txt"));
outputStream = new BufferedWriter(new FileWriter("fileTwo.txt"));
Here the unbuffered stream object is passed to the constructor for a buffered stream class.
There are four buffered stream classes used to wrap unbuffered streams: Java BufferedInputStream and Java BufferedOutputStream - BufferedOutputStream In Java create buffered byte streams, while BufferedReader In Java and Java BufferedWriter create buffered character streams.

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App