Java Writer append()方法
java.io.Writer.append(CharSequence csq) 将指定的字符序列附加到此Writer。
1 语法
public Writer append(CharSequence csq)
2 参数
csq:要追加的字符序列。如果csq为null,则将四个字符"null"追加到Writer。
3 返回值
返回Writer。
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* java.io.Writer.append(CharSequence csq)方法的例子
*/
import java.io.*;
public class Demo {
public static void main(String[] args) {
CharSequence csq = "Hello World!";
// create a new writer
Writer writer = new PrintWriter(System.out);
try {
// append a sequence and change line
writer.append("This is an example\n");
// flush the writer
writer.flush();
// append a new sequence
writer.append(csq);
// flush the writer to see the result
writer.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
输出结果为:
This is an example
Hello World!
热门文章
优秀文章