0% found this document useful (0 votes)
27 views

Java IO - Rahul Chauhan (INCAPP)

Streams are used for input and output in Java. Input streams are used to read data from an input source like the console or a file, while output streams are used to write data to an output destination like the console or a file. The Scanner class is used to get formatted input from the console, and files can also be used for input/output streams.

Uploaded by

tanzimreads
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Java IO - Rahul Chauhan (INCAPP)

Streams are used for input and output in Java. Input streams are used to read data from an input source like the console or a file, while output streams are used to write data to an output destination like the console or a file. The Scanner class is used to get formatted input from the console, and files can also be used for input/output streams.

Uploaded by

tanzimreads
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Input/Output

Stream: means flow of data.


Stream used for input purpose is known as InputStream
Stream used for output purpose is known as OutputStream

Input Input
Stream Device
Console or File
Java
Application

Output Output
Stream Device
Console or File

www.incapp.in Rahul Chauhan


Console - Input/Output

System.in

Input Console
Stream Input
Ex. Keyboard
Java
Application
System.out

Output Console
Stream Output
Ex. Console Screen

www.incapp.in Rahul Chauhan


Scanner

Scanner class is used to get input in formatted way like int, double, String, Boolean etc.
Scanner class found in java.util package.

System.in
Java Input Console
Scanner
Application Stream Input

www.incapp.in Rahul Chauhan


File - Input/Output
File - Input/Output

Input
File
Stream
Ex. Abc.txt
Java
Application

Output
File
Stream
Ex. Xyz.txt

www.incapp.in Rahul Chauhan


Type of Streams

Byte Stream
Stream that supports ASCII codes. Each Character size is 1 byte.
Example:
• FileInputStream
• FileOutputStream

Character Stream
Stream that supports Uni codes. Each Character size is 2 bytes.
Example:
• FileReader
• FileWriter

www.incapp.in Rahul Chauhan

You might also like