Java BufferedInputStream read() Example

BufferedInputStream class read() method example. This example shows you how to use read() method.


Syntax is : public int read() throws IOException
This method read tha element of buffer one by one and returns the next byte of data, or -1 if the end of the stream is reached.

Here is the code.
/**
 * @(#) ReadBufferedInputStream.java
 * A class representing use of method read() of BufferedInputStream class in 
 java.io Package.
 * @Version  03-May-2008
 @author   Rose India Team
 */
import java.io.*;
public class ReadBufferedInputStream {
     public static void main(String[] argsthrows IOException{

     
       /* Construct an buffer input stream using some String value.
        This is deprecated method in java api 1.6. */
         StringBufferInputStream obj = new StringBufferInputStream("MAHENDRA")

    // Construct the buffer using the buffer input stream obj.
        BufferedInputStream bin = new BufferedInputStream(obj);
    System.out.print("Elements in buffer : ");

    // read() method call.
        System.out.print((char)bin.read());
    System.out.print((char)bin.read());
    System.out.print((char)bin.read());
    System.out.print((char)bin.read());
    System.out.print((char)bin.read());
    System.out.print((char)bin.read());
    System.out.print((char)bin.read());
    System.out.print((char)bin.read());
    }
}

Output of the program.
Elements in buffer : MAHENDRA

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

HOME | COPYRIGHT | CONTACT US