0% found this document useful (0 votes)
12 views14 pages

Streams

Java uses streams to perform input and output operations. There are two types of streams in Java - byte streams and character streams. Byte streams handle input/output of bytes and are used for binary data/file handling, while character streams handle character input/output using Unicode encoding. The key stream classes in Java are InputStream, OutputStream for byte streams and Reader, Writer for character streams. These classes are used to read/write from the console, files and other sources.

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)
12 views14 pages

Streams

Java uses streams to perform input and output operations. There are two types of streams in Java - byte streams and character streams. Byte streams handle input/output of bytes and are used for binary data/file handling, while character streams handle character input/output using Unicode encoding. The key stream classes in Java are InputStream, OutputStream for byte streams and Reader, Writer for character streams. These classes are used to read/write from the console, files and other sources.

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/ 14

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

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 use character encoding scheme(UNICODE) while byte


oriented do not use any encoding scheme.

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

You might also like