FileOutputStream.fromFile constructor
Creates a file output stream to write to the specified File object.
Parameters
file
: The file to be opened for writingappend
: If true, bytes will be written to the end of the file rather than the beginning (default: false)
Example
final file = File('output.bin');
final output = FileOutputStream.fromFile(file);
// Append mode
final appendOutput = FileOutputStream.fromFile(file, append: true);
Throws IOException if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason.
A file output stream is an output stream for writing data to a File or to a file descriptor.
FileOutputStream is meant for writing streams of raw bytes such as image data. For writing streams of characters, consider using FileWriter.
Example Usage
// Writing binary data
final output = FileOutputStream('output.bin');
try {
final data = Uint8List.fromList([0x89, 0x50, 0x4E, 0x47]); // PNG header
await output.writeBytes(data);
await output.flush();
} finally {
await output.close();
}
// Appending to existing file
final output = FileOutputStream('log.txt', append: true);
try {
await output.writeString('New log entry\n');
await output.flush();
} finally {
await output.close();
}
Implementation
FileOutputStream.fromFile(File file, {bool append = false})
: _file = file, _append = append;