FileInputStream class
A FileInputStream obtains input bytes from a file in a file system.
FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader.
Example Usage
// Reading a binary file
final input = FileInputStream('image.png');
try {
final header = await input.readFully(8); // Read PNG header
if (isPngHeader(header)) {
final imageData = await input.readAll();
processImage(imageData);
}
} finally {
await input.close();
}
// Reading with buffer
final input = FileInputStream('data.bin');
try {
final buffer = Uint8List(1024);
int bytesRead;
while ((bytesRead = await input.read(buffer)) != -1) {
processChunk(buffer.sublist(0, bytesRead));
}
} finally {
await input.close();
}
- Inheritance
-
- Object
- InputStream
- FileInputStream
Constructors
- FileInputStream(String name)
-
Creates a FileInputStream by opening a connection to an actual file,
the file named by the path name
name
in the file system. - FileInputStream.fromFile(File file)
-
Creates a FileInputStream by opening a connection to an actual file,
the file named by the File object
file
in the file system.
Properties
- file → File
-
Returns the File object associated with this stream.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- 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
-
available(
) → Future< int> -
Returns an estimate of the number of bytes that can be read (or skipped over)
from this input stream without blocking by the next invocation of a method
for this input stream.
override
-
checkClosed(
) → void -
Checks if the stream is closed and throws an exception if it is.
inherited
-
close(
) → Future< void> -
Closes this input stream and releases any system resources associated
with the stream.
override
-
mark(
int readLimit) → void -
Marks the current position in this input stream.
inherited
-
markSupported(
) → bool -
Tests if this input stream supports the mark and reset methods.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
read(
List< int> b, [int offset = 0, int? length]) → Future<int> -
Reads some number of bytes from the input stream and stores them into
the buffer array
b
.override -
readAll(
) → Future< Uint8List> -
Reads all remaining bytes from the input stream.
inherited
-
readByte(
) → Future< int> -
Reads the next byte of data from the input stream.
override
-
readFully(
int length) → Future< Uint8List> -
Reads exactly
length
bytes from the input stream.inherited -
reset(
) → Future< void> -
Repositions this stream to the position at the time the mark method
was last called on this input stream.
inherited
-
skip(
int n) → Future< int> -
Skips over and discards
n
bytes of data from this input stream.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited