Java.io.PipedOutputStream.flush() 方法



描述

java.io.PipedOutputStream.flush() 方法重新整理此輸出流,並強制寫入任何緩衝的輸出位元組。這將通知任何讀取器管道中存在等待的位元組。

宣告

以下是 java.io.PipedOutputStream.flush() 方法的宣告。

public void flush()

引數

返回值

此方法不返回值。

異常

IOException - 如果發生 I/O 錯誤。

示例

以下示例顯示了 java.io.PipedOutputStream.flush() 方法的使用。

package com.tutorialspoint;

import java.io.*;

public class PipedOutputStreamDemo extends PipedInputStream {
   public static void main(String[] args) {
   
      // create a new Piped input and Output Stream
      PipedOutputStream out = new PipedOutputStream();
      PipedInputStreamDemo in = new PipedInputStreamDemo();

      try {
         // connect input and output
         out.connect(in);

         // write something 
         out.write(70);
         out.write(71);

         // flush the stream
         out.flush();

         // print what we wrote
         for (int i = 0; i < 2; i++) {
            System.out.println("" + (char) in.read());
         }
      } catch (IOException ex) {
         ex.printStackTrace();
      }
   }
}

讓我們編譯並執行以上程式,這將產生以下結果:

F
G
java_io_pipedoutputstream.htm
廣告

© . All rights reserved.