Input/Output Streams (I/O stream)
- A stream is defined as a continuous flow of data from one place to another. Here the flow of data is in between the program and peripherals. Hence the name input/output streams.
- Thus, in java programming, whenever we need to make a data transfer we use streams.
- The java package that supports streams is java. Io. The java.io package contains many classes using which we make the data transfer.
- For data transfer to be done, first of all the data should be represented in its low level equivalent i.e. either in the form of bytes (8 bits) or in the form of characters (16 bits).
- Depending upon the representation of the data to be transferred, the classes in the io package are classified in two categories.
- Byte oriented class
- Character oriented class
Byte oriented class:
The byte oriented classes are again classified into two sections - Classes using which we can read data and classes using which we can write data.
Character oriented classes:
Similarly, the character oriented classes are also classified into two sections- classes for reading data and classes for writing data.
Identifying the classes:
We can identify, whether a class is a byte oriented class or character oriented class with the help of the following rules, but these may not be 100% true always.
- If the last part of the name of the class is ‘stream’ then we can say that, the given class is a byte oriented class.
Example: Data Input stream, Data output stream, file input stream e. t. c…
- Similarly, if the best part of the name of the class is reader/writer then we can say that, the given class is character oriented class.
Example: Buffer Reader, file writer e. t. c …
- Whenever, it is required to transfer the data, then we should mention from where to where transfer is to be made i.e. we should mention the address of the source and destination.
- By creating objects of those classes which contain the addresses of the source and destination.