Java.io.CharArrayWriter.write() Method
Advertisements
Description
The java.io.CharArrayWriter.write(char[] c, int off, int len) method writes portion of the specified character buffer to the writer.
Declaration
Following is the declaration for java.io.CharArrayWriter.write(char[] c, int off, int len) method:
public void write(char[] c, int off, int len)
Parameters
c -- the character buffer
off -- offset from which to start reading characters
len -- number of chars to write
Return Value
The method does not return any value.
Exception
NA
Example
The following example shows the usage of java.io.CharArrayWriter.write(char[] c, int off, int len) method.
package com.tutorialspoint;
import java.io.CharArrayWriter;
public class CharArrayWriterDemo {
public static void main(String[] args) {
char[] ch = {'A','B','C','D','E'};
CharArrayWriter chw = null;
try{
// create character array writer
chw = new CharArrayWriter();
System.out.println("off = 3; len=2");
// write character buffer to the writer
chw.write(ch, 3, 2);
// get buffered content as string
String str = chw.toString();
// print the string
System.out.print(str);
}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:
off = 3; len=2 DE