OutputStream flush() Example

Flushes this output stream and forces any buffered output bytes to be written out.


OutputStream class flush() method example. This example shows you how to use flush() method.This method Flushes this output stream and forces any buffered output bytes to be written out.

Here is the code:-

/**
 * @Program that Flushes this output stream and forces any buffered output bytes
 * to be written out
 * Flush.java 
 * Author:-RoseIndia Team
 * Date:-06-Jun-2008
 */
import java.io.*;

public class Flush extends OutputStream {

    public void write(int ithrows IOException {
    }

    public static void main(String[] argsthrows Exception {
        //creating outputstream object
        OutputStream c = new PipedOutputStream();
        //creating inputstream object
        PipedInputStream pis = new PipedInputStream();
        //Connecting to the outputStream
        pis.connect((PipedOutputStreamc);
        byte[] b = {12345};
        //Writes bytes from the specified byte array to this output stream.
        c.write(b);
        //Flushes this output stream 
        c.flush();
        System.out.println("Stream before closing is");
        while (pis.available() != 0) {
            System.out.println(pis.read());
        }
        // Closes this output stream
        c.close();
        System.out.println("Stream after closing is");
        System.out.print(pis.read());
    }
}

Output of the Program
 Stream before closing is
1
2
3
4
5
Stream after closing is
-1

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US