Java IO Tutorial - Java PipedOutputStream.flush()








Syntax

PipedOutputStream.flush() has the following syntax.

public void flush()  throws IOException

Example

In the following code shows how to use PipedOutputStream.flush() method.

/*  w w  w  . j av a2s.co m*/

import java.io.PipedInputStream;
import java.io.PipedOutputStream;

public class Main extends PipedInputStream {

  public static void main(String[] args) throws Exception {
    PipedOutputStream out = new PipedOutputStream();
    Main in = new Main();

    out.connect(in);

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

    out.flush();

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

The code above generates the following result.