Java.io.StringWriter.flush() Method


Advertisements


Description

The java.io.StringWriter.flush() method flushes the stream.

Declaration

Following is the declaration for java.io.StringWriter.flush() method.

public void flush()

Parameters

  • NA

Return Value

This method does not return a value.

Exception

  • NA

Example

The following example shows the usage of java.io.StringWriter.flush() method.

package com.tutorialspoint;

import java.io.*;

public class StringWriterDemo {

   public static void main(String[] args) {

      // create a new writer
      StringWriter sw = new StringWriter();

      // create a new sequence
      String s = "Hello world";

      // write a string
      sw.write(s);

      // flush the writer
      sw.flush();

      // print result
      System.out.println("" + sw.toString());


   }
}

Let us compile and run the above program, this will produce the following result.

Hello World

java_io_stringwriter.htm

Advertisements