***Welcome to ashrafedu.blogspot.com ***This website is maintained by ASHRAF***

posts

    Java BufferedOutputStream Class

    Java BufferedOutputStream class is used for buffering an output stream. It internally uses buffer to store data. It adds more efficiency than to write data directly into a stream and makes the performance fast.

    Following is the declaration for Java.io.BufferedOutputStream class –

    public class BufferedOutputStream extends FilterOutputStream

    Java BufferedOutputStream class constructors:

    Constructor

    Description

    BufferedOutputStream(OutputStream os)

    It creates the new buffered output stream which is used for writing the data to the specified output stream.

    BufferedOutputStream(OutputStream os, int size)

    It creates the new buffered output stream which is used for writing the data to the specified output stream with a specified buffer size.

      

    Java BufferedOutputStream class methods:

    Method

    Description

    void write(int b)

    It writes the specified byte to the buffered output stream.

    void write(byte[] b, int off, int len)

    It write the bytes from the specified byte-input stream into a specified byte array, starting with the given offset

    void flush()

    It flushes the buffered output stream.

     

    Example:

    import java.io.*; 

    public class BOStreamExample{   

    public static void main(String args[])throws Exception{   

         FileOutputStream fout=new FileOutputStream("D:\\testout.txt");   

         BufferedOutputStream bout=new BufferedOutputStream(fout);   

         String s="Welcome to java class.";   

         byte b[]=s.getBytes();   

         bout.write(b);   

         bout.flush();   

         bout.close();   

         fout.close();   

         System.out.println("success");   

    }   

    } 

    No comments:

    Post a Comment