Java CharArrayWriter close() Example
CharArrayWriter class close() method example. This example shows you how to use close() method.
Syntax is : public void close()
This method closes the stream. This method does not release the buffer, since its contents might still be required. Note: Invoking this method in this class will have no effect.
Here is the code.
/**
* @(#) CloseCharArrayWriter.java
* A class representing use of method close() of CharArrayWriter class in
java.io Package.
* @Version 31-May-2008
* @author Rose India Team
*/
import java.io.*;
public class CloseCharArrayWriter {
public static void main(String[] args) throws IOException {
// Create object of CharArrayWriter class.
CharArrayWriter objCharArrWriter = new CharArrayWriter();
// append() method call.
objCharArrWriter.append("Rose ");
System.out.println("Specified char array is appended successfully!");
System.out.println("Elements in char buffer is : " + objCharArrWriter);
// close() method call.
objCharArrWriter.close();
objCharArrWriter.append("India");
System.out.println("Close() method has no effect. Again string is "
+"appended successfully!");
System.out.println("Now string buffer is : " + objCharArrWriter);
}
} |
Output of the program.
Specified char array is appended successfully!
Elements in char buffer is : Rose
Close() method has no effect. Again string is appended successfully!
Now string buffer is : Rose India |
|