Streams
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
Character oriented are tied to datatype. Only string type or character type can be read
through it while byte oriented are not tied to any datatype, data of any datatype can be
read(except string) just you have to specify it.
Character oriented reads character by character while byte oriented reads byte by byte.
Character oriented streams are also known as reader and writer streams Byte oriented
streams are known as data streams-Data input stream and Data output stream.
Concept of streams
4
Modern versions of Java define two types of streams: byte and character. (The original
version of Java defined only the byte stream, but character streams were quickly added.)
Byte streams provide a convenient means for handling input and output of bytes. They
are used, for example, when reading or writing binary data. They are especially helpful
when working with files.
Character streams are designed for handling the input and output of characters. They
use Unicode and, therefore, can be internationalized. Also, in some cases, character
streams are more efficient than byte streams.
The Console: System.out, System.in, and System.err
5
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.
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.
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
6
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
7
InputStream class, OutputStream class
8
InputStream class, OutputStream class
9
FileInputStreams class
10
FileOutputStreams class
11
Reader class and Writer class
12
Reader class
13
Writer class
14