BufferedWriter flush Example
BufferedWriter class flush example. This example shows you how to use flush method.
BufferedWriter class flush example.public void flush() throws IOException Flushes the stream.
Here is the code
/**
* @ # Flush.java
* A class repersenting use to flush method
* of BufferedWriter class in java.io package
* version 29 May 2008
* author Rose India
*/
import java.io.*;
public class Flush {
public static void main(String[] args) throws Exception {
// Create a new instance of a BufferedWriter object using
// a StringWriter.
StringWriter stringWriter = new StringWriter();
BufferedWriter bufWriter = new BufferedWriter(stringWriter);
// Write to the underlying StringWriter.
String s = "This is the string being written.";
bufWriter.write(s);
bufWriter.flush();
System.out.println(stringWriter.getBuffer());
// Close the BufferedWriter object and the underlying
// StringWriter object.
stringWriter.close();
bufWriter.close();
}
} |
Output
| This is the string being written. |
|