Click here to watch in Youtube :
Click the below Image to Enlarge
Java Tutorial : Java IO (StringWriter) |
Java Tutorial : Java IO (StringWriter) |
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();
}
}
}
}
Outputstr = Welcome to India
sb = Welcome to India
Refer: https://docs.oracle.com/javase/8/docs/api/index.html?java/io/StringWriter.html
No comments:
Post a Comment