Streams
Streams
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.
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.
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
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