Java StringWriter close() Example
StringWriter class close() method example. This example shows you how to use close() method.
Syntax is : public void close() throws IOException
Closing a StringWriter has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.
Here is the code.
/**
* @(#) CloseStringWriter.java
* A class representing use of method close() of StringWriter class in
java.io Package.
* @Version 28-May-2008
* @author Rose India Team
*/
import java.io.*;
public class CloseStringWriter {
public static void main(String[] args) throws IOException {
// Create object of StringWriter class.
StringWriter objStringWriter = new StringWriter();
// append() method call.
objStringWriter.append("Rose ");
System.out.println("Specified string is appended successfully!");
System.out.println("String in string buffer is : " + objStringWriter);
objStringWriter.close();
objStringWriter.append("India");
System.out.println("Close() method has no effect. Again string is "
+"appended successfully!");
System.out.println("Now string buffer is : " + objStringWriter);
}
} |
Output of the program.
Specified string is appended successfully!
String in string buffer is : Rose
Close() method has no effect. Again string is appended successfully!
Now string buffer is : Rose India |
|