[go: up one dir, main page]

0% found this document useful (0 votes)
14 views27 pages

Streams

Java uses streams to perform input and output operations. There are two types of streams: byte streams which handle 8-bit bytes for binary data, and character streams which handle 16-bit Unicode characters. The main streams in Java are System.in for standard input, System.out for standard output, and System.err for standard error output. These streams connect to the console by default. Classes like FileInputStream, FileOutputStream, FileReader and FileWriter are used to perform file input/output operations.

Uploaded by

subhanshujha5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views27 pages

Streams

Java uses streams to perform input and output operations. There are two types of streams: byte streams which handle 8-bit bytes for binary data, and character streams which handle 16-bit Unicode characters. The main streams in Java are System.in for standard input, System.out for standard output, and System.err for standard error output. These streams connect to the console by default. Classes like FileInputStream, FileOutputStream, FileReader and FileWriter are used to perform file input/output operations.

Uploaded by

subhanshujha5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 27

1

Java Programming

Java Input/Output
Concept of streams
2

Java I/O (Input and Output) is used to process the input and produce the output.

Java uses the concept of a stream to make I/O operation fast. The java.io package
contains all the classes required for input and output operations.

We can perform file handling in Java by Java I/O API.

Stream

A stream is a sequence of data. In Java, a stream is composed of bytes. It's called a


stream because it is like a stream of water that continues to flow.
Concept of streams
3
Concept of streams
4
Concept of streams
5
Concept of streams
6

Byte Stream and Character Stream.

•Byte streams are used to perform input and output of 8-bit bytes. When
we want to read/write binary data, we can use byte streams.

•The character stream is used to perform 16-bit Unicode input and output
operations. Character streams are used to read and write characters.
Concept of streams
7
Concept of streams
8
Concept of streams
9
Difference between Byte Stream and Character
Stream:
10
Difference between Byte Stream and Character
Stream:
11
Concept of streams
12
The Console: System.out, System.in, and System.err
13

All the programming languages provide support for standard I/O where the user's program can take
input from a keyboard and then produce an output on the computer screen. Similarly, Java provides
the following three standard streams:

Standard Input:

This is used to feed the data to user's program and usually a keyboard is used as a standard input
stream and represented as System.in.

System.in is an InputStream which is typically connected to keyboard input of console programs.

The keyboard input can typically be read via System.in from inside that Java application. However,
it is only keyboard input directed to that Java application (the console / terminnal that started the
application) which can be read via System.in.
The Console: System.out, System.in, and System.err
14
The Console: System.out, System.in, and System.err
15

Standard Output:

This is used to output the data produced by the user's program and usually a computer screen is
used for standard output stream and represented as System.out.
The Console: System.out, System.in, and System.err
16

Standard Error:

This is used to output the error data produced by the user's program and usually a computer screen
is used for standard error stream and represented as System.err.
The Console: System.out, System.in, and System.err
17

The console is the default destination for output written to System.out or System.err and
the default source of input for System.in .

On most platforms the console is the command-line environment from which the Java
program was initially launched.
InputStream class, OutputStream class
18
InputStream class, OutputStream class
19
InputStream class, OutputStream class
20
FileInputStreams class
21
FileOutputStreams class
22
Reader class and Writer class
23
Reader class
24
Reader class
25

FileReader class in Java

The "FileReader" class is used for reading the data (contents) of a file.
This class is a child class of the Reader class
Writer class
26
Writer class
27

Java FileWriter Class


Java FileWriter class is used to write character-oriented data to a file. It is
character-oriented class which is used for file handling in java.

You might also like