Java Writer.write(char[] cbuf, int off, int len)
Syntax
Writer.write(char[] cbuf, int off, int len) has the following syntax.
public abstract void write(char[] cbuf, int off, int len) throws IOException
Example
In the following code shows how to use Writer.write(char[] cbuf, int off, int len) method.
/*from ww w. j av a 2 s . c om*/
import java.io.*;
public class Main {
public static void main(String[] args) {
char[] c = {'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm'};
Writer writer = new PrintWriter(System.out);
try {
// write a portion of a char array
writer.write(c, 0, 5);
// flush the writer
writer.flush();
// write another portion of a char array
writer.write(c, 5, 5);
// flush the stream again
writer.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »