java.io.CharArrayWriter.write(char[] c, int off, int len)方法实例
java.io.CharArrayWriter.write(char[] c, int off, int len) 方法写入指定的字符的缓冲区到writer。
声明
以下是 java.io.CharArrayWriter.write(char[] c, int off, int len) 方法的声明:
public void write(char[] c, int off, int len)
参数
-
c -- 字符缓冲区
-
off -- 从偏移量开始读取字符
-
len -- 要写入的字符数
返回值
该方法不返回任何值。
异常
-
NA
例子
下面显示java.io.CharArrayWriter.write(char[] c, int off, int len)方法的例子。
package com.yiibai; 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(); } } }
让我们来编译和运行上面的程序,这将产生以下结果:
off = 3; len=2 DE