Share on Google+Share on Google+

Java file StringWriter

his section demonstrates you the use of StringWriter class.

Java file StringWriter

This section demonstrates you the use of StringWriter class.

StringWriter is a character stream that collects its output in a string buffer, which can then be used to construct a string. In other words, you can say it enables to obtain the characters written to a Writer as a string. Closing a StringWriter has no effect.

append(): This method of StringWriter class appends the specified character to the writer.

write(): This method of StringWriter class write the string to the writer.

Here is the code:


public class FileStringWriter {
	public static void main(String[] args) throws Exception {
		StringWriter obj = new StringWriter();
		obj.append("Rose ");
		obj.append("India ");
		obj.write("Technologies Pvt Ltd");
		System.out.println("String: " + obj);

The above code will definitely explains you the concept of StringWriter.



Posted on: April 26, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.