Java StringWriter write() Example

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


Syntax is : public void write(char[] cbuf, int off, int len)
This method writes a subArray of specified array to StringWriter buffer.

Here is the code.
/**
 * @(#) WriteStringWriter.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 WriteStringWriter {
     public static void main(String[] args){

         char arrChar[] {' ','P','v','t','.',' ','i','n','d','i','a'};
    // 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(arrChar,0,5);
    System.out.println("After writing a sub array StringBuffer is : "+obj);
    }
}

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

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

HOME | COPYRIGHT | CONTACT US