java.io.CharArrayWriter.append(CharSequence csq, int start, int end) 方法將指定的字元序列的一部分到這個writer。
以下是java.io.CharArrayWriter.append(CharSequence csq, int start, int end)方法的宣告:
public CharArrayWriter append(CharSequence csq, int start, int end)
csq - 字元序列進行追加。如果字元序列為空,writer被追加4個字元'null'。
start -- 在該部分中的第一個字元的索引
end -- 字元的子序列結束後的指數
當前CharArrayWriter
IndexOutOfBoundsException -- 如果end大於序列length,start大於end,或start或end是負的。
下面的例子顯示java.io.CharArrayWriter.append(CharSequence csq, int start, int end)方法。
package com.yiibai; import java.io.CharArrayWriter; public class CharArrayWriterDemo { public static void main(String[] args) { CharArrayWriter chw = null; try{ // create character array writer chw = new CharArrayWriter(); // declare character sequence CharSequence csq = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // append character sequence to the writer chw.append(csq, 2, 5); // prints out the character sequences 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(); } } }
讓我們來編譯和執行上面的程式,這將產生以下結果:
CDE