Java CharArrayWriter append()方法
java.io.CharArrayWriter.append(CharSequence csq) 用于将指定的字符序列附加到Writer。
1 语法
public CharArrayWriter append(CharSequence csq)
2 参数
csq:要追加的字符序列。如果字符序列为空,则在CharArrayWriter后追加4个字符“Null”。
3 返回值
返回CharArrayWriter。
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* java.io.CharArrayWriter.append(CharSequence csq)方法的例子
*/
import java.io.CharArrayWriter;
public class Demo {
public static void main(String[] args) {
CharArrayWriter chw = null;
try {
// create character array writer
chw = new CharArrayWriter();
// declare character sequences
CharSequence csq = "12345 ";
CharSequence csq1 = "67890 ";
CharSequence csq2 = "ABCDE ";
CharSequence csq3 = "abcde ";
// append character sequences to the writer
chw.append(csq);
chw.append(csq1);
chw.append(csq2);
chw.append(csq3);
// 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();
}
}
}
输出结果为:
12345 67890 ABCDE abcde
热门文章
优秀文章