StringWriter.close() has the following syntax.
public void close() throws IOException
In the following code shows how to use StringWriter.close() method.
import java.io.*; /*from w ww . j a v a2s. co m*/ public class Main { public static void main(String[] args) { StringWriter sw = new StringWriter(); // create a new sequence String s = "Hello from java2s.com"; // write a string sw.write(s); System.out.println(sw.toString()); try { // close the writer sw.close(); } catch (IOException ex) { ex.printStackTrace();; } } }
The code above generates the following result.