Java BufferedOutputStream flush() Example
BufferedOutputStream class flush() method example. This example shows you how to use flush() method.
Syntax is : public void flush() throws IOException
Method flushes this buffered output stream. This forces any buffered output bytes to be written out to the underlying output stream.
Here is the code.
/**
* @(#) FlushBufferedOutputStream.java
* A class representing use of method flush() of BufferedOutputStream
class in java.io Package.
* @Version 05-May-2008
* @author Rose India Team
*/
import java.io.*;
public class FlushBufferedOutputStream {
public static void main(String[] args) throws IOException{
String str = "MAHENDRA";
System.out.println("Elements in buffer are : " + str);
// Create object of FileOutputStream class.
FileOutputStream objFileStream = new FileOutputStream("MAHENDRA");
// Create object of BufferedOutputStream class.
BufferedOutputStream obj = new BufferedOutputStream(objFileStream);
// flush() method call.
obj.flush();
System.out.print("flush() method is called that forces buffered out "+
"bytes \nto be written out to the underlying output stream.");
}
} |
Output of the program.
Elements in buffer are : MAHENDRA
flush() method is called that forces buffered out bytes
to be written out to the underlying output stream. |
|