Common methods of BufferedOutputStream class in Java

BufferedOutputStream byte buffered output stream

The construction method is in the
first development) public BufferedOutputStream (OutputStream out):
the default buffer size (enough enough) to construct a byte buffered output stream object
public BufferedOutputStream (OutputStream out, int size):
specify the size buffer Area size construction buffer output stream object
IllegalArgumentException-if size <= 0

Common methods
public void write (int b) throws IOException
write one byte at a time
b-the byte to be written.

public void write (byte [] b, int off, int len) throws IOException
writes a part of a byte array
b-data at a time.
off-the starting offset of the data.
len-the number of bytes to be written.
 
public void flush () throws IOException
Flush this buffered output stream. This forces all buffered output bytes to be written out to the underlying output stream.

public void close () throws IOException
closes this output stream and releases all system resources related to this stream.
The close method of FilterOutputStream first calls its flush method, and then calls the close method of its basic output stream.

Program example

public  static  void main (String [] args) throws Exception {    
     // In line with a Java design pattern: decorator design pattern (filter: Filter) 
    BufferedOutputStream bos = new BufferedOutputStream ( new FileOutputStream ("bos.txt" ));
        
    // write data 
    bos.write ("hello" .getBytes ( ));
     // release resources 
    bos.close ();
}

 


Original link: https://blog.csdn.net/scbiaosdo/article/details/80422490

Guess you like

Origin www.cnblogs.com/liuminchao/p/12695932.html