Java LineNumberInputStream read() Example

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


Syntax is : public int read(byte[] b, int off, int len) throws IOException
Method reads up to len bytes of data from this input stream into an array of bytes, method blocks until some input is available. This is deprecated method of deprecated class.

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

         // Declare the buffer and initialize its size:
         byte[] arrByte = new  byte[1024];

       /* Create object of StringBufferInputStream class. This is deprecated 
       class in java api 1.6. */
        StringBufferInputStream obj = new StringBufferInputStream("Mahendra");

    // Create object of LineNumberInputStream class.
    LineNumberInputStream objInputStream = new LineNumberInputStream(obj)
     int c = 0;
         System.out.print("Elements in buffer : ");
       
         // Read from the buffer one character at a time:
          while ((c = objInputStream.read(arrByte, 0, arrByte.length)) >= 0){
              for (int i = 0; i < c; i++) {

                // Display the read byte:
                System.out.print((char)arrByte[i]);
              }
          }
   }
}

Output of the program.
Elements in buffer are : Mahendra

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

HOME | COPYRIGHT | CONTACT US