Java.io.PrintStream.append() 方法
描述
java.io.PrintStream.append() 方法将指定的字符序列附加到此输出流中。
声明
以下是 java.io.PrintStream.append() 方法的声明。
public PrintStream append(CharSequence csq)
参数
csq − 要追加的字符序列。 如果 csq 为 null,则将四个字符"null"附加到此输出流中。
返回值
此方法返回此输出流。
异常
NA
示例
下面的例子展示了 java.io.PrintStream.append() 方法的使用。
package com.tutorialspoint;
import java.io.*;
public class PrintStreamDemo {
public static void main(String[] args) {
String s = "Hello World. ";
// create printstream object
PrintStream ps = new PrintStream(System.out);
// append our strings
ps.append(s);
ps.append("This is an example.");
// print the result
ps.flush();
ps.close();
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Hello World. This is an example.

