FileOutputStream class
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();
}
- Inheritance
-
- Object
- OutputStream
- FileOutputStream
Constructors
- FileOutputStream(String name, {bool append = false})
- Creates a file output stream to write to the file with the specified name.
- FileOutputStream.fromFile(File file, {bool append = false})
- Creates a file output stream to write to the specified File object.
Properties
- file → File
-
Returns the File object associated with this stream.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isAppendMode → bool
-
Returns whether this stream is in append mode.
no setter
- isClosed → bool
-
Returns
true
if this stream has been closed.no setterinherited - position → int
-
Returns the current position in the file.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
checkClosed(
) → void -
Checks if the stream is closed and throws an exception if it is.
inherited
-
close(
) → Future< void> -
Closes this output stream and releases any system resources associated
with this stream.
override
-
flush(
) → Future< void> -
Flushes this output stream and forces any buffered output bytes to be
written out.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
write(
List< int> b, [int offset = 0, int? length]) → Future<void> -
Writes
b.length
bytes from the specified byte array to this output stream.override -
writeByte(
int b) → Future< void> -
Writes the specified byte to this output stream.
override
-
writeBytes(
Uint8List data) → Future< void> -
Writes all bytes from the specified Uint8List to this output stream.
inherited
-
writeString(
String str) → Future< void> -
Writes a string to this output stream using UTF-8 encoding.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited