BufferedWriter class
Writes text to a character-output stream, buffering characters to provide efficient writing of characters, arrays, and strings.
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 writing
final buffered = BufferedWriter(FileWriter('output.txt'));
try {
await buffered.write('Hello, World!');
await buffered.writeLine('This is a new line.');
await buffered.flush();
} finally {
await buffered.close();
}
// Writing large amounts of data efficiently
final buffered = BufferedWriter(FileWriter('large_output.txt'), bufferSize: 65536);
try {
for (int i = 0; i < 10000; i++) {
await buffered.writeLine('Record $i: ${generateLargeString()}');
}
await buffered.flush();
} finally {
await buffered.close();
}
Constructors
- BufferedWriter(Writer writer, {int bufferSize = _defaultBufferSize})
- Creates a buffering character-output stream that uses a default-sized output buffer.
Properties
Methods
-
append(
int c) → Future< Writer> -
Appends the specified character to this writer.
inherited
-
appendString(
String? csq) → Future< Writer> -
Appends the specified character sequence to this writer.
inherited
-
checkClosed(
) → void -
Checks if the writer is closed and throws an exception if it is.
inherited
-
close(
) → Future< void> -
Closes the writer and releases any system resources associated with it.
override
-
flush(
) → Future< void> -
Flushes the buffer and ensures all data is written to the underlying writer.
override
-
newLine(
) → Future< void> -
Writes a line separator.
inherited
-
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 off = 0, int? len]) → Future< void> -
Writes a string to the buffer.
override
-
writeChar(
int c) → Future< void> -
Writes a single character to the buffer.
override
-
writeChars(
List< int> buf, [int off = 0, int? len]) → Future<void> -
Writes a portion of a character array to the buffer.
override
-
writeLine(
[String? str]) → Future< void> -
Writes a line of text to the buffer.
override
-
writeObject(
Object? obj) → Future< void> -
Writes the string representation of an object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited