Java.io.CharArrayWriter.write() Method
Advertisements
Description
The java.io.BufferedInputStream.write(String str, int off, int len) method writes a part of the string to the writer.
Declaration
Following is the declaration for java.io.CharArrayWriter.write(String str, int off, int len) method:
public void write(String str, int off, int len)
Parameters
str -- Source string
off -- Offset to start reading the characters from
len -- Number of characters to be written
Return Value
This method does not return any value.
Exception
NA
Example
The following example shows the usage of java.io.CharArrayWriter.write(String str, int off, int len) method.
package com.tutorialspoint;
import java.io.CharArrayWriter;
public class CharArrayWriterDemo {
public static void main(String[] args) {
String str = "Hello World!!";
CharArrayWriter chw = null;
try{
// create character array writer
chw = new CharArrayWriter();
// portion to be written to writer
chw.write(str, 4, 9);
// print the buffer as string
System.out.println(chw.toString());
}catch(Exception e){
// for any error
e.printStackTrace();
}finally{
// releases all system resources from writer
if(chw!=null)
chw.close();
}
}
}
Let us compile and run the above program, this will produce the following result:
o World!!