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