# readChar method

1. @override

Future<int> readChar()
override

Reads a single character.

This method will block until a character is available, an I/O error occurs, or the end of the stream is reached.

## Returns

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

## Example

    final reader = FileReader('text.txt');
    try {
      int char;
      while ((char = await reader.readChar()) != -1) {
        print('Character: ${String.fromCharCode(char)}');
      }
    } finally {
      await reader.close();
    }

Throws IOException if an I/O error occurs. Throws StreamClosedException if the reader has been closed.

## Implementation

    @override
    Future<int> readChar() async {
      await _ensureOpen();

      if (_buffer == null || _bufferPosition >= _buffer!.length) {
        return -1; // End of file
      }

      final char = _buffer!.codeUnitAt(_bufferPosition);
      _bufferPosition++;
      return char;
    }