Writer class abstract
Abstract class for writing to character streams.
The only methods that a subclass must implement are writeChar, flush, and close. Most subclasses, however, will override some of the methods defined here in order to provide higher efficiency, additional functionality, or both.
Design Philosophy
The Writer class provides a uniform interface for writing character data to various destinations. Unlike OutputStream which deals with raw bytes, Writer handles character encoding and provides text-oriented operations.
Example Usage
// Writing to a file
final writer = FileWriter('output.txt');
try {
await writer.write('Hello, World!');
await writer.writeLine('This is a new line.');
await writer.flush();
} finally {
await writer.close();
}
// Writing with buffering for better performance
final bufferedWriter = BufferedWriter(FileWriter('large_output.txt'));
try {
for (int i = 0; i < 1000; i++) {
await bufferedWriter.writeLine('Line $i: Some content here');
}
await bufferedWriter.flush(); // Ensure all data is written
} finally {
await bufferedWriter.close();
}
- Implemented types
- Implementers
Constructors
- Writer()
- Abstract class for writing to character streams.
Properties
Methods
-
append(
int c) → Future< Writer> - Appends the specified character to this writer.
-
appendString(
String? csq) → Future< Writer> - Appends the specified character sequence to this writer.
-
checkClosed(
) → void - Checks if the writer is closed and throws an exception if it is.
-
close(
) → Future< void> -
Closes the stream, flushing it first.
override
-
flush(
) → Future< void> -
Flushes the stream.
override
-
newLine(
) → Future< void> - Writes a line separator.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
write(
String str, [int offset = 0, int? length]) → Future< void> - Writes a string.
-
writeChar(
int c) → Future< void> - Writes a single character.
-
writeChars(
List< int> cbuf, [int offset = 0, int? length]) → Future<void> - Writes an array of characters.
-
writeLine(
[String? str]) → Future< void> - Writes a string followed by a line separator.
-
writeObject(
Object? obj) → Future< void> - Writes the string representation of an object.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited