目录

void flush()

描述 (Description)

java.io.PipedOutputStream.flush()方法刷新此输出流并强制写出任何缓冲的输出字节。 这将通知任何读者字节在管道中等待。

声明 (Declaration)

以下是java.io.PipedOutputStream.flush()方法的声明。

public void flush()

参数 (Parameters)

NA

返回值 (Return Value)

此方法不返回值。

异常 (Exception)

IOException - 如果发生I/O错误。

例子 (Example)

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

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018