readAll method
Reads all remaining characters from the reader.
This method reads from the current position until the end of the reader is reached. The returned string contains all the characters that were read.
Returns
A String containing all remaining characters in the reader.
Example
final reader = FileReader('document.txt');
try {
final content = await reader.readAll();
print('Document content:');
print(content);
} finally {
await reader.close();
}
Throws IOException if an I/O error occurs. Throws StreamClosedException if the reader has been closed.
Implementation
Future<String> readAll() async {
checkClosed();
final buffer = StringBuffer();
final charBuffer = List<int>.filled(8192, 0); // 8KB buffer
int charsRead;
while ((charsRead = await read(charBuffer)) != -1) {
buffer.write(String.fromCharCodes(charBuffer.sublist(0, charsRead)));
}
return buffer.toString();
}