PrintWriter flush Example
PrintWriter class flush example. This example shows you how to use flush method.
PrintWriter class flush example. public void flush() Flushes the stream.
Here is the code
/**
* @ # Flush.java
* A class reprsenting use to flush method
* of PrintWriter class in java.io package
* version 10 June 2008
* author Rose India
*/
import java.io.*;
public class Flush {
public static void main(String args[]) throws Exception {
// Create a new instance of a PrintWriter object along with
// an underlying StringWriter object.
String s = new String("Roseindia");
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
stringWriter.flush();
//Write a string.
stringWriter.write(s);
// Appends a String into the writer.
printWriter.append(".Net");
System.out.println(stringWriter.getBuffer());
// Close the PrintWriter and String Writer objects.
stringWriter.close();
printWriter.close();
}
} |
|