Java CharArrayWriter reset() Example
CharArrayWriter class reset() method example. This example shows you how to use reset() method.
Syntax is : public void reset()
This method resets the buffer so that you can use it again without throwing away the already allocated buffer.
Here is the code.
/**
* @(#) ResetCharArrayWriter.java
* A class representing use of method reset() of CharArrayWriter
class in java.io Package.
* @Version 03-June-2008
* @author Rose India Team
*/
import java.io.*;
public class ResetCharArrayWriter {
public static void main(String[] args) throws IOException{
// Create a new object of CharArrayWriter class.
CharArrayWriter charWriter = new CharArrayWriter();
// Append some character sequence.
CharArrayWriter obj = charWriter.append("Mahendra ");
System.out.println("Elements in buffer : " + obj);
obj = charWriter.append("Singh");
System.out.println("After append some elements, buffer is : " + obj);
// reset() method call.
obj.reset();
System.out.println("After reset() elements in buffer : " + obj);
System.out.print("buffer is empty now,you can append some values.");
}
} |
Output of the program.
Elements in buffer : Mahendra
After append some elements, buffer is : Mahendra Singh
After reset() elements in buffer :
buffer is empty now,you can append some values. |
|