CharArrayReader read() in Java

read(): This method is available in the java.io.CharArrayReader class of Java.

Syntax:

int java.io.CharArrayReader.read() throws IOException

This method reads a single character.

Parameters: NA

Returns: The character read, as an integer in the range 0 to 65535(0x00-0xffff), or -1 if the end of the stream has been reached.

Throws:

IOException - If an I/O error occurs

Approach

Java

import java.io.CharArrayReader;
import java.io.IOException;

public class CharArrayReaderread {

    public static void main(String[] args) throws IOException {
        char buf[] = { 'a', 'b', 'c', 'd' };
        CharArrayReader charArrayReader =
new CharArrayReader(buf);

        System.out.println(charArrayReader.read());
        charArrayReader.close();

    }
}

Output:

97


No comments:

Post a Comment