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, int off, int len)
This method writes a substring of specified string to StringWriter buffer.
Here is the code.
/**
* @(#) Write3StringWriter.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 Write3StringWriter {
public static void main(String[] args){
String str = "India Pvt. Ltd";
// 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, 5, 5);
System.out.println("After writing a substring StringBuffer is : "+ obj);
}
} |
Output of the program.
String in string buffer is : Rose India
After writing a substring StringBuffer is : Rose India Pvt. |
|