BufferedReader class

Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.

The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.

Example Usage

// Basic buffered reading
final buffered = BufferedReader(FileReader('document.txt'));
try {
  String? line;
  while ((line = await buffered.readLine()) != null) {
    print('Line: $line');
  }
} finally {
  await buffered.close();
}

// Using mark and reset for lookahead
final buffered = BufferedReader(FileReader('config.txt'));
try {
  buffered.mark(1024);
  
  final firstLine = await buffered.readLine();
  if (firstLine?.startsWith('<?xml') == true) {
    await buffered.reset(); // Go back to beginning
    processAsXml(buffered);
  } else {
    await buffered.reset(); // Go back to beginning
    processAsText(buffered);
  }
} finally {
  await buffered.close();
}
Inheritance

Constructors

BufferedReader(Reader reader, {int bufferSize = _defaultBufferSize})
Creates a buffering character-input stream that uses a default-sized input buffer.

Properties

hashCode int
The hash code for this object.
no setterinherited
isClosed bool
Returns true if this reader has been closed.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

checkClosed() → void
Checks if the reader is closed and throws an exception if it is.
inherited
close() Future<void>
Closes the stream and releases any system resources associated with it.
inherited
mark(int readAheadLimit) → void
Marks the present position in the stream.
inherited
markSupported() bool
Tells whether this stream supports the mark() operation.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read(List<int> cbuf, [int offset = 0, int? length]) Future<int>
Reads characters into an array.
override
readAll() Future<String>
Reads all remaining characters from the reader.
inherited
readChar() Future<int>
Reads a single character.
override
readLine() Future<String?>
Reads a line of text.
override
ready() Future<bool>
Tells whether this stream is ready to be read.
override
reset() Future<void>
Resets the stream.
inherited
skip(int n) Future<int>
Skips characters.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited