Java LineNumberInputStream read() Example
LineNumberInputStream class read() method example. This example shows you how to use read() method.
Syntax is : public int read() throws IOException
Method reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This is deprecated method of deprecated class.
Here is the code.
/**
* @(#) ReadLineNumberInputStream.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 ReadLineNumberInputStream {
public static void main(String[] args) throws IOException{
/* 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);
// Read from the buffer one character at a time:
System.out.println("First element is : "+(char)objInputStream.read());
System.out.println("Next element is : "+(char)objInputStream.read());
System.out.println("Next element is : "+(char)objInputStream.read());
System.out.println("Next element is : "+(char)objInputStream.read());
System.out.println("Next element is : "+(char)objInputStream.read());
System.out.println("Next element is : "+(char)objInputStream.read());
System.out.println("Next element is : "+(char)objInputStream.read());
System.out.println("Next element is : "+(char)objInputStream.read());
}
} |
Output of the program.
First element is : M
Next element is : A
Next element is : H
Next element is : E
Next element is : N
Next element is : D
Next element is : R
Next element is : A |
|