Java IO Tutorial - Java StringWriter.getBuffer()


StringWriter.getBuffer() has the following syntax.

public StringBuffer getBuffer()


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

//from w  w  w  . j  av  a 2s .c o m

public class Main {

   public static void main(String[] args) {

      StringWriter sw = new StringWriter();

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

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


The code above generates the following result.