FileInputStream constructor
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.
Parameters
name
: The system-dependent filename
Example
final input = FileInputStream('data.bin');
try {
final data = await input.readAll();
processData(data);
} finally {
await input.close();
}
Throws IOException if the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading.
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();
}
Implementation
FileInputStream(String name) : _file = File(name);