Writer Flush() Example
Flushes the stream.
Writer class Flush() method example. This example shows you how to use Flush() method.This method Flushes the stream.
Here is the code:-
/**
* @Program that Flush the stream.
* Flush.java
* Author:-RoseIndia Team
* Date:-5-jun-2008
*/
import java.io.*;
public class Flush {
public static void main(String[] args) throws IOException{
// Create a StringWriter object.
StringWriter writer = new StringWriter();
// Write some data to the StringWriter object.
char[] arr = new char[] {'R', 'o', 's', 'e',
' ', 'I', 'n', 'd', 'i', 'a' };
for (int i = 0; i < arr.length; i++)
{
writer.write(arr[i]);
}
// Print out the contents of the StringWriter buffer.
System.out.println("The StringWriter buffer contains: " +
writer.getBuffer().toString());
// flush the buffer we populated.
writer.flush();
// Print out the contents of the StringWriter buffer.
System.out.println("The flush StringWriter buffer " +
"contains: " + writer.getBuffer().toString());
// Close the StringWriter buffer.
writer.close();
}
} |
Output of the Program
The StringWriter buffer contains: Rose India
The flush StringWriter buffer contains: Rose India |
|