Java StringWriter flush() Example
StringWriter class flush() method example. This example shows you how to use flush() method.
Syntax is : public void flush()
This method flushes the stream. Actually flush makes sure everything you have written so far is committed to the hard disk, and the expanded file length is also committed to the disk directory, with the updated lastModified timestamp committed too. When you flush a console, flush guarantees every byte you have written so far is displayed on screen.
Here is the code.
/**
* @(#) FlushStringWriter.java
* A class representing use of method flush() of StringWriter class in
java.io Package.
* @Version 29-May-2008
* @author Rose India Team
*/
import java.io.*;
public class FlushStringWriter {
public static void main(String[] args){
// Create object of StringWriter class
StringWriter objStringWriter = new StringWriter();
// append() method call.
objStringWriter.append("Rose ");
System.out.println("String in string buffer is : " + objStringWriter);
// flush() method call.
objStringWriter.flush();
System.out.println("After use flush() buffer is : "+objStringWriter);
}
} |
Output of the program.
String in string buffer is : Rose
After use flush() buffer is : Rose |
|