StringWriter flush Example

StringWriter class flush example. This example shows you how to use flush method.


StringWriter class flush example. flush method invoked anywhere will flush or flow the running stream and generate the buffered output of the program.

Here is the code:-
/**
 * @Program uses flush method to flush or explicitly flow the underlying stream 
 * running inside StringWriter class.
 * Flush.java 
 * Author:-RoseIndia Team
 * Date:-9-july-2008
 */

import java.io.StringWriter;

public class Flush {
  public static void main(String args[]) {
    StringWriter cozy = new StringWriter();
    // flushing the sream soon has no impact on the called methods
    cozy.flush();
    cozy.append('u');
    cozy.append('r');
    cozy.append('g');
    cozy.append('e');
    String magneto = cozy.toString();
    StringBuffer a = new StringBuffer(magneto);

    System.out.println(a + " to know java ");
    System.out.println("roseindia welcomes you all");
    // flushes the stream after printing String buffered
    // output in to the underlying stream.
    cozy.flush();

  }
}

Output of the program:-
urge to know java
roseindia welcomes you all

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US