Advertisement
BufferedOutputStream(OutputStream os) |
---|
This constructor creates a BufferedOutputStream object to write a chunk of byte to a file, which is accessed by an OutputStream. Example-:
|
Methods | Description |
---|---|
flush() | This method flushes any buffered data to be written out of this output stream. |
write(int b) | This method writes one byte at a time to this output stream. |
write(byte[]) | This method writes a whole byte array at a time to this output stream. |
close() | This method closes this outut stream and also frees any resources connected with this output stream. |
Advertisement
//Program to create a BufferedIOutputStream to write(one byte at a time) out to an existing file.
import java.io.*;
class A
{
public static void main(String... ar)
{
String str="Java is the best programming language";
byte b[]=str.getBytes();
try
{
FileOutputStream fos= new FileOutputStream("D://TextBook.txt");
BufferedOutputStream bos= new BufferedOutputStream(fos); ///A local buffer is created which is big-
//enough to hold a chunk of bytes to be
//written out to a file TextBook.txt
bos.write(b); //writes to local buffer
bos.flush();
bos.close();
fos.close();
}
catch(IOException e)
{
System.out.println(e);
}
}
}
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement