0% found this document useful (0 votes)
10 views13 pages

Unit 5

The document provides an overview of I/O programming in Java, detailing the classification of input and output streams into byte-oriented and character-oriented categories. It explains key classes such as InputStream, OutputStream, Reader, and Writer, along with their subclasses for handling data efficiently. Additionally, it covers object I/O, serialization, and deserialization processes, highlighting the use of ObjectOutputStream and ObjectInputStream for reading and writing objects.

Uploaded by

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

Unit 5

The document provides an overview of I/O programming in Java, detailing the classification of input and output streams into byte-oriented and character-oriented categories. It explains key classes such as InputStream, OutputStream, Reader, and Writer, along with their subclasses for handling data efficiently. Additionally, it covers object I/O, serialization, and deserialization processes, highlighting the use of ObjectOutputStream and ObjectInputStream for reading and writing objects.

Uploaded by

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

Unit 4

Archana NS
Department of Computer Applications
Don Bosco College
TC Palya
I/O Programming

Stream
• A flow of information from source to
destination.
• Keyboard and monitor
• A file on hardware and a monitor
Byte oriented
classes / Binary
streams
• Input Stream
Classificati • Output stream
on of I/O
streams Character oriented
classes / Text
streams.
• Reader
• Writer
Input stream class is the super
class of all the classes which are
used to read data in the form of
bytes.
Classificati Output stream class is the super
on of I/O classes of all the classes which are
streams used to write data in the form of
characters.

Object is the super class of all the


streams.
Used to read bytes
from the input stream
Byte/ and write bytes to the
Binary output stream.
stream Defined by using two
class
hierarchies.InputStrea
m and OutputStream.
• Binary input streams read data in the form of
bytes from a source.
• The main classes for input streams include
InputStream and its
subclasses.
InputStrea Key Subclasses of InputStream:
• FileInputStream: Reads bytes from a file.
m • ByteArrayInputStream: Reads bytes from an
array.
• BufferedInputStream: Buffers the input for
efficient reading.
• DataInputStream: Allows reading of primitive
data types in a machine-independent way.
Binary output streams write data in the
form of bytes to a destination.
The main classes for output streams
include OutputStream and its
subclasses.
FileOutputStream: Writes bytes to a file.
OutputStre
am ByteArrayOutputStream: Writes bytes to
an array.
BufferedOutputStream: Buffers the
output for efficient writing.
DataOutputStream: Allows writing of
primitive data types in a machine-
independent way.
Character streams in Java are used for handling
the input and output of character data.
They are part of the java.io package and are
Character designed to facilitate reading and writing of
text data.
Stream/ Character streams handle data in 16-bit
Text Unicode

Streams Character streams are categorized into two


main types:

Reader (for reading character data)

Writer (for writing character data)


The Reader class is the abstract base class for all
character input streams. It provides methods for reading
characters, arrays, and lines.
Key Subclasses of Reader:

FileReader: Reads characters from a file.

Reader BufferedReader: Buffers characters for efficient reading.

InputStreamReader: Bridges from byte streams to


character streams (can wrap an InputStream).

StringReader: Reads characters from a String.


The Writer class is the abstract base class for all
character output streams. It provides methods for
writing characters, arrays, and strings.
Key Subclasses of Writer:

FileWriter: Writes characters to a file.

Writer BufferedWriter: Buffers characters for efficient writing.

OutputStreamWriter: Bridges from character streams to


byte streams (can wrap an OutputStream).

StringWriter: Writes characters to a String


Object I/O in Java refers to the
process of reading and writing
objects to and from streams,
enabling the serialization and
deserialization of objects.
This is particularly useful for saving
the state of an object to a file or
Object I/O transferring objects over a network.

Java provides the java.io package


which includes ObjectOutputStream
and ObjectInputStream for this
purpose.
Serialization
and Serialization is the Deserialization is the
process of converting reverse process, where
Deserializati an object into a byte a byte stream is
stream, which can be converted back into a
on easily saved to a file or copy of the original
sent over a network. object.
ObjectOutputStream
• ObjectOutputStream is used to write objects to
an output stream. It extends OutputStream and
implements ObjectOutput.
• writeObject(Object obj): Writes the specified
object to the ObjectOutputStream.
ObjectInputStream
Key Classes • ObjectInputStream is used to read objects from
an input stream.
• It extends InputStream and implements
ObjectInput.
• readObject(): Reads an object from the
ObjectInputStream.

You might also like