Thursday 22 September 2016

Java Tutorial : Java IO (StringWriter constructor accept initialSize)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=SxblW-lnbRQ&list=UUhwKlOVR041tngjerWxVccw

StringWriterDemo.java
import java.io.StringWriter;

/*
 * public StringWriter(int initialSize)
 * 
 * Parameters: 
 * ----------
 * 
 * initialSize - The number of char values that will fit
 * into this buffer before it is automatically expanded
 */

public class StringWriterDemo
{

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

            // 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

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_StringWriter_Cons_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_StringWriter_Cons_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/8270b2c7cbb37f975ee9fc66e47a041db3aa4063/BasicJava/JavaIODemo_StringWriter_Cons_App/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment