What is a Stream and use of it

Stream :

Stream is a connection between Java Program and a File.

Stream is not a physical wired connection but a logical connection for transferring data.

Stream is a logical connection between java program and file either for reading or writing.

Basically there are two types of Streams :

  • Input Stream
  • Output Stream

These streams are from the java point of view i.e with respect to java. Hence we can say
– Input Stream w.r.t to java is give input to java program.
– Output Stream w.r.t to java is give output from java program.

Broadly there are 4 types of Streams in java :

  • Binary Streams – For binary data – From java 1.0
    • Input Stream (Abstract Class)
    • Output Stream (Abstract Class)
  • Characters Streams – For characters – From java 1.1
    • Reader (Abstract Class)
    • Writer (Abstract Class)
  • Input and Output Stream are abstract class
  • Since there are several sources to read data from and several destination to write data to hence we need several concrete classes which extends this abstract class and handle the logic.

List of Input Streams : (9 subclasses)

  1. FileInputStream (Read one byte Data from File as it is) (Important)
  2. ByteArrayInputStream (Read data inform of array)
  3. FilterInputStream
    1. DataInputStream (Read one byte Data from File in primitive datatype)(Important)
    2. BufferedInputStream (Reading Fast )
  4. ObjectInputStream (Reading as a complete Object)(Important)
  5. PipedInputStream (Passing a Stream to another)
  6. SequenceInputStream (Read Data from multiple file)
  7. StringBufferInputStream

List of Output Streams : (8 subclasses)

  1. FileOutputStream
  2. ByteArrayOutputStream
  3. FilterOutputStream
    1. DataOutputStream
    2. BufferedOutputStream
    3. PrintStream
  4. ObjectOutputStream
  5. PipedOutputStream

Leave a Comment