PrintWriter append Example
PrintWriter class append example. This example shows you how to use append method.
PrintWriter class append example. public PrintWriter append(CharSequence , int , int ) Appends a subsequence of the specified character sequence to this writer.
Here is the code
/**
* @ # Append2.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 Append2 {
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 String into the writer.
printWriter.append(".Net....",0,4);
System.out.println(stringWriter.getBuffer());
// Close the PrintWriter and String Writer objects.
stringWriter.close();
printWriter.close();
}
} |
|