void flush()
描述 (Description)
java.io.PrintWriter.flush()方法刷新流。
声明 (Declaration)
以下是java.io.PrintWriter.flush()方法的声明。
public void flush()
参数 (Parameters)
NA
返回值 (Return Value)
此方法不返回值。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.io.PrintWriter.flush()方法的用法。
package com.iowiki;
import java.io.*;
public class PrintWriterDemo {
public static void main(String[] args) {
String s = "Hello World";
try {
// create a new stream at specified file
PrintWriter pw = new PrintWriter(System.out);
// write the string in the file
pw.write(s);
// flush the writer
pw.flush();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
Hello World