Java.io.PrintStream.flush() 方法
描述
java.io.PrintStream.flush() 方法刷新流。 这是通过将任何缓冲的输出字节写入底层输出流然后刷新该流来完成的。
声明
以下是 java.io.PrintStream.flush() 方法的声明。
public void flush()
参数
NA
返回值
此方法不返回值。
异常
NA
示例
下面的例子展示了 java.io.PrintStream.flush() 方法的使用。
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);
// print our string
ps.print(s);
// flush the stream to see the results
ps.flush();
// print new string
ps.println();
ps.print("This is an example");
// flush to see new string
ps.flush();
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Hello World. This is an example

