Menu
Topics Index
...
`

CharArrayReaderDemo - Java Example Program


CharArrayReaderDemo
import java.io.*;

class CharArrayReaderDemo
{
    public static void main(String arg[])
    {
        String quote = "Merit Campus -Your Online Java School.";
        char c[] = quote.toCharArray(); // LINE A
        CharArrayReader car = new CharArrayReader(c); // LINE B
        System.out.println("Is ready : " + car.ready()); // LINE C
        int i;
        while( (i = car.read()) != -1) // LINE D
        System.out.print((char)i);
        
        car.close(); //    
    }
}
OUTPUT

Is ready : true
Merit Campus -Your Online Java School.

DESCRIPTION

At LINE A we are converting the Sting to charArray.
At LINE B we created a CharArrayReader object to read characters from c in a stream manner.
At LINE C we are checking whether stream is ready or not.
At LINE D we are reading character from Stream.
At LINE E we are closing the stream.

THINGS TO TRY
  • Convert the String I LOVE PROGRAMMING in to char array and read characters in stream manner..
  • Mark at P in the String and read 4 characters.
  • Reset the stream.

© meritcampus 2019

All Rights Reserved.

Open In App