The perfect place for easy learning...

Java Programming


Topics List

Stream in java

In java, the IO operations are performed using the concept of streams. Generally, a stream means a continuous flow of data. In java, a stream is a logical container of data that allows us to read from and write to it. A stream can be linked to a data source, or data destination, like a console, file or network connection by java IO system. The stream-based IO operations are faster than normal IO operations.

The Stream is defined in the package.

To understand the functionality of java streams, look at the following picture.

IO streams in java

In java, the stream-based IO operations are performed using two separate streams input stream and output stream. The input stream is used for input operations, and the output stream is used for output operations. The java stream is composed of bytes.

In Java, every program creates 3 streams automatically, and these streams are attached to the console.

  • System.out: standard output stream for console output operations.
  • standard input stream for console input operations.
  • System.err: standard error stream for console error output operations.

The Java streams support many different kinds of data, including simple bytes, primitive data types, localized characters, and objects.

Java provides two types of streams, and they are as follows.

  • Byte Stream
  • Character Stream

The following picture shows how streams are categorized, and various built-in classes used by the java IO system.

IO streams in java

Both character and byte streams essentially provides a convenient and efficient way to handle data streams in Java.

In the next tutorial, we will explore different types of streams in java.