Sunday, 11 June 2017

Java Tutorial : Java IO (StringWriter) ~ foundjava


Click here to watch in Youtube :

Click the below Image to Enlarge
Java Tutorial : Java IO (StringWriter) 
Java Tutorial : Java IO (StringWriter) 
StringWriterDemo.java
import java.io.StringWriter;

public class StringWriterDemo
{

    public static void main(String[] args) throws Exception
    {
        StringWriter stringWriter = null;
        try
        {
            /*
             * Create a new string writer using the default
             * initial string-buffer size.
             */
            stringWriter = new StringWriter();

            // write characters to writer.
            stringWriter.write("Welcome to India");

            /*
             * Return the buffer's current value as a
             * string.
             */
            String str = stringWriter.toString();
            System.out.println("str = " + str);
            /*
             * Returns: StringBuffer holding the current
             * buffer value.
             */
            StringBuffer sb = stringWriter.getBuffer();
            System.out.println("sb = " + sb);

        }
        finally
        {
            if (stringWriter != null)
            {
                stringWriter.close();
            }
        }
    }
}
Output
str = Welcome to India
sb = Welcome to India
Refer: 
https://docs.oracle.com/javase/8/docs/api/index.html?java/io/StringWriter.html
Click the below link to download the code:

CLICK HERE

No comments:

Post a Comment