Open In App

Java.io.BufferedOutputStream class in Java

Java.io.BufferedInputStream class in Java

Java.io.BufferedOutputStream class implements a buffered output stream. By setting up such an output stream, an application can write bytes to the underlying output stream without necessarily causing a call to the underlying system for each byte written.

Fields

Constructor and Description

Methods:

Program:




//Java program demonstrating BufferedOutputStream
  
import java.io.*;
  
class BufferedOutputStreamDemo
{
    public static void main(String args[])throws Exception
    {
        FileOutputStream fout = new FileOutputStream("f1.txt");
          
        //creating bufferdOutputStream obj
        BufferedOutputStream bout = new BufferedOutputStream(fout);
  
        //illustrating write() method
        for(int i = 65; i < 75; i++)
        {
            bout.write(i);
        }
          
        byte b[] = { 75, 76, 77, 78, 79, 80 };
        bout.write(b);
  
        //illustrating flush() method
        bout.flush();
          
        //illustrating close() method
        bout.close();
        fout.close();
    }
}

Output :

ABCDEFGHIJKLMNOP

Article Tags :