PrintWriter append Example
PrintWriter class append example. This example shows you how to use append method.
PrintWriter class append example. public PrintWriter append(char c) Appends the specified character to this writer. An invocation of this method of the form out.append(c) behaves in exactly the same way as the invocation
Here is the code
/**
* @ # Append.java
* A class reprsenting use to Append method
* of PrintWriter class in java.io package
* version 10 June 2008
* author Rose India
*/
import java.io.*;
public class Append {
public static void main(String args[]) throws Exception {
// Create a new instance of a PrintWriter object along with
// an underlying StringWriter object.
String s = new String("Roseindia");
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
//Write a string.
stringWriter.write(s);
// Appends a character into the writer.
printWriter.append('.');
System.out.println(stringWriter.getBuffer());
// Close the PrintWriter and String Writer objects.
stringWriter.close();
printWriter.close();
}
} |
|