Input Streams( Java)

date
Jan 10, 2024
slug
java-streams
status
Published
tags
STREAMS
summary
type
Post

Streams

In Java programming, streams serve as the fundamental mechanism for transmitting data between different components. For example between two programs, between program and file, and so on.
In others words, it is stream is flow of data(bytes) from program to external component or to program from external component.
 

InputStream

 
notion image
Inputstream serve as mechanism for receving data from external component to the program. It provides a structured interface that allows the program to sequentially read bytes or characters from the source.
 

Some Types of Input Streams

 

ByteArrayInputStream

This type of source allows reading bytes from a byte array. It is often used when you have data stored in memory that you want to read from.
 
notion image
 
For example:
 

FileInputStream

This type of input stream allows reading bytes from a file from the local filesystem. It is commonly used when you want to read data from a file.
 
notion image
 

System.in

This type of stream is used to read data from standard input eg console.
 
Code
notion image
 
Output Explanation for Input 10: 1 in ASCI is 49, 0 in ASCI 48 and \n is 10

© Rupesh Dang 2021 - 2025