his section demonstrates you the use of StringWriter class.
his section demonstrates you the use of StringWriter class.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:
import java.io.*;
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.