close method

  1. @override
  2. @mustCallSuper
Future<void> close()
override

Closes the stream and releases any system resources associated with it.

Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.

Example

final reader = FileReader('data.txt');
try {
  final content = await reader.readAll();
  processContent(content);
} finally {
  await reader.close(); // Always close in finally block
}

Throws IOException if an I/O error occurs.

Implementation

@override
@mustCallSuper
Future<void> close() async {
  _closed = true;
}