A stream concept at the io level is a file (generally a text file)
A stream is an abstract concept for files and io devices which can be read or written, or sometimes both.
Stream I/O (input/output) refers to the transfer of data either to or from a storage medium. Streams are a mean to manipulate the data that is read or written from and to a file (from byte to characters, object ,…).
For instance, a file content is an ordered collection of bytes and you manipulate this sequence of byte through the creation of a stream that gives you methods to read from and write to and from destinations such as:
- a hardware device (disk, memory)
- a file,
- or a program component
Reading or writing a large amount of data can be resource-intensive. You should perform these tasks asynchronously if your application needs to remain responsive to the user. With synchronous I/O operations, the thread is blocked until the resource-intensive operation has completed. Use asynchronous I/O operations when developing apps to prevent creating the impression that your app has stopped working.
Data source and destination
A stream can represent many different kinds of:
- and destinations
that holds, generates, or consumes data.
- disk files,
- another program,
- a peripheral device,
- or an (memory)array.
Typically, streams are designed for simple byte input and output but they can supports many different kinds of data including:
- primitive data types,
- localized characters,
- and objects.
Some streams simply pass on data; others manipulate and transform the data.
A program uses an input stream to read data sequentially (one item at time) from a source.
A program uses an output stream to write data sequentially (one item at time) to a destination.
- Several languages, such as Perl and Python, implement streams as iterators.