OutputStream close() Example

Closes this output stream and releases any system resources associated with this stream.


OutputStream class close() method example. This example shows you how to use close() method.This method Closes this output stream and releases any system resources associated with this stream.

Here is the code:-

/**
 * @Program that Closes this output stream and releases any system resources
 * associated with this stream.
 * Close.java 
 * Author:-RoseIndia Team
 * Date:-06-Jun-2008
 */
import java.io.*;

public class Close 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};
        //c.write(b, 0, 5);
        //Writes b.length bytes from the specified byte array to this output stream.
        c.write(b);
        // 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