Writer constructor

Writer()

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();
}

Implementation

Writer();