Java IO Tutorial - Java StringWriter.getBuffer()








Syntax

StringWriter.getBuffer() has the following syntax.

public StringBuffer getBuffer()

Example

In the following code shows how to use StringWriter.getBuffer() method.

//from w  w  w  . j  av  a 2s .c o m
import java.io.*;

public class Main {

   public static void main(String[] args) {

      
      StringWriter sw = new StringWriter();

      // write a string
      sw.write("tutorial from java2s.com");

      // print result by getting the buffer
      System.out.println("" + sw.getBuffer());


   }
}

The code above generates the following result.