writeChars method
Writes an array of characters.
Parameters
cbuf: Array of characters to writeoffset: Offset from which to start writing characters (default: 0)length: Number of characters to write (default: remaining characters from offset)
Example
final writer = FileWriter('output.txt');
try {
final chars = 'Hello, World!'.codeUnits;
// Write entire array
await writer.writeChars(chars);
// Write part of array
await writer.writeChars(chars, 7, 5); // Write "World"
await writer.flush();
} finally {
await writer.close();
}
Throws InvalidArgumentException if offset or length is negative, or if
offset + length is greater than the length of cbuf.
Throws IOException if an I/O error occurs.
Throws StreamClosedException if the writer has been closed.
Implementation
@override
Future<void> writeChars(List<int> cbuf, [int offset = 0, int? length]) async {
await _ensureOpen();
length ??= cbuf.length - offset;
if (offset < 0 || length < 0 || offset + length > cbuf.length) {
throw InvalidArgumentException('Invalid offset or length');
}
for (int i = 0; i < length; i++) {
_buffer.add(cbuf[offset + i] & 0xFFFF);
}
}