PipedOutputStream close Example

PipedOutputStream class close example. This example shows you how to use close method.


PipedOutputStream class close example.public void close() throws IOException Closes this piped output stream and releases any system resources associated with this stream. This stream may no longer be used for writing bytes.

Here is the code

/**
 * @ # Close.java
 * A class repersenting use to close method 
 * of PipedOutputStream class in java.io package
 * version 03 June 2008
 * author Rose India 
 */
import java.io.*;

public class Close {

    public static void main(String args[]) throws Exception {
        
        PipedOutputStream poStream = new PipedOutputStream();
        PipedInputStream piStream = new PipedInputStream();
        
        // Connects piped output stream to a receiver.
        poStream.connect(piStream);

        //write byte array
        byte b[] {12345};
        poStream.write(b, 05);
        
        //Flushes output stream
        poStream.flush();
        
        System.out.println("Read from piped input stream");
        while (piStream.available() != 0) {
            System.out.println(piStream.read());
        }
        
        //Reads the next byte from piped input stream.
        poStream.close();
        piStream.close();
    }
}

Output
Read from piped input stream
1
2
3
4
5

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

HOME | COPYRIGHT | CONTACT US