Java.io.PipedWriter.flush()方法實例
java.io.PipedWriter.flush() 方法刷新此輸出流並強製寫出所有緩衝的輸出字符。這將通知字符守候在管道的任何讀取器。
聲明
以下是java.io.PipedWriter.flush()方法的聲明
public void flush()
參數
-
NA
返回值
此方法不返回任何值。
異常
-
IOException -- 如果發生I/ O錯誤。
例子
下麵的示例演示java.io.PipedWriter.flush()方法的用法。
package com.yiibai; import java.io.*; public class PipedWriterDemo { public static void main(String[] args) { // create a new Piped writer and reader PipedWriter writer = new PipedWriter(); PipedReader reader = new PipedReader(); try { // connect the reader and the writer writer.connect(reader); // write something writer.write(70); writer.write(71); // flush the writer System.out.println("Flushing writer..."); writer.flush(); System.out.println("Writer flushed."); // print what we wrote for (int i = 0; i < 2; i++) { System.out.println("" + (char) reader.read()); } } catch (IOException ex) { ex.printStackTrace(); } } }
讓我們編譯和運行上麵的程序,這將產生以下結果:
Flushing writer... Writer flushed. F G