Java StringWriter Class

Java StringWriter class is a character stream that collects output from string buffer, which can be used to construct a string. The StringWriter class inherits the Writer class.

In StringWriter class, system resources like network sockets and files are not used, therefore closing the StringWriter is not necessary.

Class declaration

public class StringWriter extends Writer

Methods of PrintWriter class

  1. void write(int c)

    It is used to write the single character.

  2. void write(String str)

    It is used to write the string.

  3. void write(String str, int off, int len)

    It is used to write the portion of a string.

  4. void write(char[] cbuf, int off, int len)

    It is used to write the portion of an array of characters.

  5. String toString()

    It is used to return the buffer current value as a string.

  6. StringBuffer getBuffer()

    It is used t return the string buffer.

  7. StringWriter append(char c)

    It is used to append the specified character to the writer.


Example :

Flash Soon


Output:



Advertisement

© Sapster 2017