import java.io.StringWriter;
import java.io.IOException;

public class JavaStringWriterExample
{
   public static void main(String args[])
    {
       String str = "Java StringWriter Example";
       
       try {

                StringWriter sw = new StringWriter();
                sw.write(str);
                StringBuffer sb = new StringBuffer();
                sb = sw.getBuffer();
                System.out.println();
                System.out.println("StringBuffer = "+sb);
                System.out.println("String written by StringWriter = "+ sw);
                System.out.println();
                sw.close();                
             }
        catch (IOException e)
            {
               System.out.println(e);
            }
      }
}