描述
所述java.io.Writer.append(CharSequence csq,int start,int end))方法将指定字符序列到这个写入器的亚序列。附加。
声明
以下是java.io.Writer.append()方法的声明。
public Writer append(CharSequence csq,int start,int end)
参数
csq - 要追加的字符序列。如果csq为null,则将四个字符“null”附加到此writer。
start - 子序列中第一个字符的索引。
end - 子序列中最后一个字符后面的字符的索引。
返回值
此方法返回此writer。
异常
IndexOutOfBoundsException - 如果start或end为负数,则start大于end,或者end大于csq.length()。
IOException - 如果发生I / O错误。
实例
以下示例显示了java.io.Writer.append()方法的用法。
package com.tutorialspoint;
import java.io.*;
public class WriterDemo {
public static void main(String[] args) {
CharSequence csq = "Hello World!";
// create a new writer
Writer writer = new PrintWriter(System.out);
try {
// append a subsequence and change line
writer.append("This is an examplen", 11, 19);
// flush the writer
writer.flush();
// append a new subsequence
writer.append(csq, 0, 5);
// flush the writer to see the result
writer.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
让我们编译并运行上面的程序,这将产生以下结果
example
Hello