Java StringWriter write() Example

StringWriter class write() method example. This example shows you how to use write() method.


Syntax is : public void write(String str)
This method writes a String to StringWriter buffer.

Here is the code.
/**
 * @(#) Write2StringWriter.java
 * A class representing use of method write() of StringWriter class in 
 java.io Package.
 * @Version  29-May-2008
 @author   Rose India Team
 */
import java.io.*;
public class Write2StringWriter {
     public static void main(String[] args){

         String str = " Pvt.";
    // Create object of StringWriter class
        StringWriter obj = new StringWriter();
        // append() method call.
        obj.append("Rose ");
    obj.append("India");
        System.out.println("String in string buffer is : " + obj);
    // write() method call.
    obj.write(str);
    System.out.println("After writing a string StringBuffer is : "+obj);
    }
}

Output of the program.
String in string buffer is : Rose India
After writing a string StringBuffer is : Rose India Pvt.

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US