Java IO Tutorial - Java StringWriter.write(String str)








Syntax

StringWriter.write(String str) has the following syntax.

public void write(String str)

Example

In the following code shows how to use StringWriter.write(String str) method.

/*w  w  w  .j  a v a2 s  .  c  o m*/
import java.io.*;

public class Main {

   public static void main(String[] args) {
      String s = "tutorial from java2s.com";
     
      StringWriter sw = new StringWriter();

      // write strings
      sw.write(s);
      sw.write(" World");

      System.out.println(sw.toString());


   }
}

The code above generates the following result.