OutputStream Write1() Example

Writes b.length bytes from the specified byte array to this output stream.


OutputStream class Write1() method example. This example shows you how to use Write1() method.This method Writes b.length bytes from the specified byte array to this output stream.

Here is the code:-

/**
 * @Program that Writes bytes from the specified byte array to output stream.
 * Write1.java 
 * Author:-RoseIndia Team
 * Date:-06-Jun-2008
 */
import java.io.*;

public class Write1 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);
        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