InputStream Available() Example

Returns an estimate of the number of bytes that can be read from this input stream


InputStreamclass Available() method example. This example shows you how to use Available() method.This method Returns an estimate of the number of bytes that can be read from this input stream

Here is the code:-

/**
 * @Program that  Returns an estimate of the number of bytes that can be read 
   from this input stream
 * Available.java 
 * Author:-RoseIndia Team
 * Date:-06-Jun-2008
 */
import java.io.*;

public class Available extends InputStream {

    public int read() throws IOException {
        return 0;
    }

    public static void main(String[] argsthrows IOException {
        PipedInputStream i = new PipedInputStream();
        OutputStream o = new PipedOutputStream();
        i.connect((PipedOutputStreamo);
        byte[] b = {1234567};
        o.write(b);
    System.out.print("The estimate of the number of bytes that can be read : ");
    //Returns an estimate of the number of bytes that can be read   
    while (i.available() != 0) {
    System.out.print(" "+i.read());
        }
        i.close();
    }
}

Output of the Program
 The estimate of the number of bytes that can be read :  1 2 3 4 5 6 7

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

HOME | COPYRIGHT | CONTACT US