SlideShare a Scribd company logo
4
Most read
6
Most read
7
Most read
Standard input, output and
error
Lecture Under Construction
Contents
• Overview of I/O Streams
• Character Streams
• Byte Streams
• Using the Streams
• Object Serialization
• Working with Random Access files
• Standard IO Streams
Overview of I/O Streams
To bring in information, a program opens
a stream on an information source (a file,
memory, a socket) and reads the
information sequentially, as shown in the
following figure.
Similarly, a program can send
information to an external destination
by opening a stream to a destination
and writing the information out
sequentially, as shown in the following
figure.
Overview of I/O STREAMS
Contd.
Overview of I/O streams
Contd..
• The java.io package contains a collection
of stream classes that support algorithms
for reading and writing. To use these
classes, a program needs to import the
java.io package.
• The stream classes are divided into two
class hierarchies, based on the data type
(either characters or bytes) on which they
operate i.e Character Stream and Byte
Stream
Character Streams
• Reader and Writer are the abstract
superclasses for character streams in
java.io.
• Reader provides the API and partial
implementation for readers ( streams
that read 16-bit characters ) and
Writer provides the API and partial
implementation for writers ( streams
that write 16-bit characters).
Character Streams Contd.
• The following figure shows the class
hierarchies for the Reader and Writer
classes.
Byte Streams
• To read and write 8-bit bytes,
programs should use the byte streams,
descendents of InputStream and
OutputStream .
• InputStream and OutputStream
provide the API and partial
implementation for input streams
(streams that read 8-bit bytes) and
output streams (streams that write 8-
bit bytes).
Byte Streams (cont.)
• These streams are typically used to
read and write binary data such as
images and sounds.
• Two of the byte stream classes,
ObjectInputStream and
ObjectOutputStream, are used for
object serialization.
Byte Streams (cont.)
• The class hierarchy for the Reader Class
Byte Stream (cont.)
• Class hierarchy figure for Writer Class
How to Use File Streams
The file streams-- FileReader , FileWriter ,
FileInputStream , and FileOutputStream -- read or
write from a file on the native file system.
Here is simple code to create a file reader
File inputFile = new File("farrago.txt");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
This reads characters from the reader as long as
there's more input in the input file and writes
those characters to the writer.
How to Use Pipe Streams
• Pipes are used to channel the output
from one thread into the input of
another. PipedReader and PipedWriter
(and their input and output stream
counterparts PipedInputStream and
PipedOutputStream ) implement the
input and output components of a
pipe.
How to wrap a stream
Streams are wrapped to combine the various
features of the many streams.
example code:
BufferedReader in = new
BufferedReader(source);
The code opens a BufferedReader on source,
which is another reader of a different type.
This essentially "wraps" source in a
BufferedReader. The program reads from the
BufferedReader, which in turn reads from
source.
How to Concatenate Files
• The SequenceInputStream creates a single
input stream from multiple input sources.
example code :
ListOfFiles mylist = new ListOfFiles(args);
SequenceInputStream s = new
SequenceInputStream(mylist);
Here, the mylist object is an enumeration
that SequenceInputStream uses to get a new
InputStream whenever it needs one.
Working with Filter Streams
• The java.io package provides a set of abstract
classes that define and partially implement
filter streams. A filter stream filters data as it's
being read from or written to the stream.
• The filter streams are FilterInputStream , and
FilterOutputStream .
• A filter stream is constructed on another
stream (the underlying stream).
Object Serialization
• Two stream classes in java.io,
ObjectInputStream and
ObjectOutputStream, are used to read
and write objects.
• The key to writing an object is to
represent its state in a serialized form
sufficient to reconstruct the object as it
is read. This process is called object
serialization.
Uses of Object Serialization
• Remote Method Invocation (RMI)--
communication between objects via
sockets
• Lightweight persistence--the archival
of an object for use in a later
invocation of the same program.
Working with Random
Access Files
• A random access file permits non-sequential or
random access to a file's contents.
• Using Random Access Files
Unlike the input and output stream classes in
java.io, RandomAccessFile is used for both
reading and writing files. You create a
RandomAccessFile object with different
arguments depending on whether you intend
to read or write.
Standard IO Streams
• There are three standard streams, all of which
are managed by the java.lang.System class
• Standard input--referenced by System.in
– Used for program input, typically reads input
entered by the user.
• Standard output--referenced by System.out
– Used for program output, typically displays
information to the user.
• Standard error--referenced by System.err
– Used to display error messages to the user.
References
• http://java.sun.com/docs/books/tutori
al/essential/TOC.html#io
• http://www.codeguru.com/java/tij/tij
0114.shtml

More Related Content

PPT
Java interfaces
PPTX
Java awt (abstract window toolkit)
PPTX
JAVA AWT
PPTX
Dynamic method dispatch
PDF
Java I/o streams
PPT
Exception Handling in JAVA
PPTX
Exception handling c++
PPT
Applet life cycle
Java interfaces
Java awt (abstract window toolkit)
JAVA AWT
Dynamic method dispatch
Java I/o streams
Exception Handling in JAVA
Exception handling c++
Applet life cycle

What's hot (20)

PDF
Java Thread Synchronization
PPTX
File handling
PPTX
I/O Streams
PDF
input/ output in java
PPT
Java Streams
PPTX
Constructor and Types of Constructors
PPT
Swing and AWT in java
PPTX
Vectors in Java
PPT
Java: GUI
PPTX
Exception handling
PPTX
Event handling
PPTX
Event Handling in java
PPT
9. Input Output in java
PPTX
Types of Constructor in C++
PDF
Java IO
PPTX
Java package
PPTX
Java exception handling
PDF
Java thread life cycle
PDF
PPTX
L21 io streams
Java Thread Synchronization
File handling
I/O Streams
input/ output in java
Java Streams
Constructor and Types of Constructors
Swing and AWT in java
Vectors in Java
Java: GUI
Exception handling
Event handling
Event Handling in java
9. Input Output in java
Types of Constructor in C++
Java IO
Java package
Java exception handling
Java thread life cycle
L21 io streams
Ad

Similar to Input output streams (20)

PPT
Md121 streams
PPTX
Javaiostream
PDF
11_Str11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.eams.pdf
PDF
Monhocvecaujahetvagiuplaptunhhayhonha.pdf
PDF
Basic IO
PPTX
PPTX
Input output files in java
PPTX
Files io
DOC
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
PPTX
Java Input Output (java.io.*)
PPT
Using Input Output
PDF
What is java input and output stream?
PDF
What is java input and output stream?
PDF
IOstreams hgjhsgfdjyggckhgckhjxfhbuvobunciu
PDF
javaiostream
PDF
Javaiostream
PPT
Java development development Files lectur6.ppt
PPT
IO and serialization
PDF
UNIT4-IO,Generics,String Handling.pdf Notes
Md121 streams
Javaiostream
11_Str11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.eams.pdf
Monhocvecaujahetvagiuplaptunhhayhonha.pdf
Basic IO
Input output files in java
Files io
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
Java Input Output (java.io.*)
Using Input Output
What is java input and output stream?
What is java input and output stream?
IOstreams hgjhsgfdjyggckhgckhjxfhbuvobunciu
javaiostream
Javaiostream
Java development development Files lectur6.ppt
IO and serialization
UNIT4-IO,Generics,String Handling.pdf Notes
Ad

More from Parthipan Parthi (20)

PPTX
Inheritance
PPTX
Switch statement mcq
PPTX
Oprerator overloading
PPTX
802.11 mac
PPT
Ieee 802.11 wireless lan
PPTX
Computer network
PPT
Ieee 802.11 wireless lan
PPTX
Session 6
PPT
Queuing analysis
PPTX
Alternative metrics
PPT
PPT
Ieee 802.11 wireless lan
PPTX
Data structures1
PPTX
Data structures 4
PPTX
Data structures2
PPTX
Data structures 3
PPT
Io stream
DOC
Dbms lab questions
PPTX
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
Inheritance
Switch statement mcq
Oprerator overloading
802.11 mac
Ieee 802.11 wireless lan
Computer network
Ieee 802.11 wireless lan
Session 6
Queuing analysis
Alternative metrics
Ieee 802.11 wireless lan
Data structures1
Data structures 4
Data structures2
Data structures 3
Io stream
Dbms lab questions
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3

Recently uploaded (20)

PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
Event Presentation Google Cloud Next Extended 2025
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
CroxyProxy Instagram Access id login.pptx
PDF
DevOps & Developer Experience Summer BBQ
PDF
Modernizing your data center with Dell and AMD
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
cuic standard and advanced reporting.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Transforming Manufacturing operations through Intelligent Integrations
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Event Presentation Google Cloud Next Extended 2025
Chapter 2 Digital Image Fundamentals.pdf
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Review of recent advances in non-invasive hemoglobin estimation
CroxyProxy Instagram Access id login.pptx
DevOps & Developer Experience Summer BBQ
Modernizing your data center with Dell and AMD
NewMind AI Monthly Chronicles - July 2025
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
cuic standard and advanced reporting.pdf
Understanding_Digital_Forensics_Presentation.pptx
Big Data Technologies - Introduction.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Transforming Manufacturing operations through Intelligent Integrations

Input output streams

  • 3. Contents • Overview of I/O Streams • Character Streams • Byte Streams • Using the Streams • Object Serialization • Working with Random Access files • Standard IO Streams
  • 4. Overview of I/O Streams To bring in information, a program opens a stream on an information source (a file, memory, a socket) and reads the information sequentially, as shown in the following figure.
  • 5. Similarly, a program can send information to an external destination by opening a stream to a destination and writing the information out sequentially, as shown in the following figure. Overview of I/O STREAMS Contd.
  • 6. Overview of I/O streams Contd.. • The java.io package contains a collection of stream classes that support algorithms for reading and writing. To use these classes, a program needs to import the java.io package. • The stream classes are divided into two class hierarchies, based on the data type (either characters or bytes) on which they operate i.e Character Stream and Byte Stream
  • 7. Character Streams • Reader and Writer are the abstract superclasses for character streams in java.io. • Reader provides the API and partial implementation for readers ( streams that read 16-bit characters ) and Writer provides the API and partial implementation for writers ( streams that write 16-bit characters).
  • 8. Character Streams Contd. • The following figure shows the class hierarchies for the Reader and Writer classes.
  • 9. Byte Streams • To read and write 8-bit bytes, programs should use the byte streams, descendents of InputStream and OutputStream . • InputStream and OutputStream provide the API and partial implementation for input streams (streams that read 8-bit bytes) and output streams (streams that write 8- bit bytes).
  • 10. Byte Streams (cont.) • These streams are typically used to read and write binary data such as images and sounds. • Two of the byte stream classes, ObjectInputStream and ObjectOutputStream, are used for object serialization.
  • 11. Byte Streams (cont.) • The class hierarchy for the Reader Class
  • 12. Byte Stream (cont.) • Class hierarchy figure for Writer Class
  • 13. How to Use File Streams The file streams-- FileReader , FileWriter , FileInputStream , and FileOutputStream -- read or write from a file on the native file system. Here is simple code to create a file reader File inputFile = new File("farrago.txt"); FileReader in = new FileReader(inputFile); FileWriter out = new FileWriter(outputFile); This reads characters from the reader as long as there's more input in the input file and writes those characters to the writer.
  • 14. How to Use Pipe Streams • Pipes are used to channel the output from one thread into the input of another. PipedReader and PipedWriter (and their input and output stream counterparts PipedInputStream and PipedOutputStream ) implement the input and output components of a pipe.
  • 15. How to wrap a stream Streams are wrapped to combine the various features of the many streams. example code: BufferedReader in = new BufferedReader(source); The code opens a BufferedReader on source, which is another reader of a different type. This essentially "wraps" source in a BufferedReader. The program reads from the BufferedReader, which in turn reads from source.
  • 16. How to Concatenate Files • The SequenceInputStream creates a single input stream from multiple input sources. example code : ListOfFiles mylist = new ListOfFiles(args); SequenceInputStream s = new SequenceInputStream(mylist); Here, the mylist object is an enumeration that SequenceInputStream uses to get a new InputStream whenever it needs one.
  • 17. Working with Filter Streams • The java.io package provides a set of abstract classes that define and partially implement filter streams. A filter stream filters data as it's being read from or written to the stream. • The filter streams are FilterInputStream , and FilterOutputStream . • A filter stream is constructed on another stream (the underlying stream).
  • 18. Object Serialization • Two stream classes in java.io, ObjectInputStream and ObjectOutputStream, are used to read and write objects. • The key to writing an object is to represent its state in a serialized form sufficient to reconstruct the object as it is read. This process is called object serialization.
  • 19. Uses of Object Serialization • Remote Method Invocation (RMI)-- communication between objects via sockets • Lightweight persistence--the archival of an object for use in a later invocation of the same program.
  • 20. Working with Random Access Files • A random access file permits non-sequential or random access to a file's contents. • Using Random Access Files Unlike the input and output stream classes in java.io, RandomAccessFile is used for both reading and writing files. You create a RandomAccessFile object with different arguments depending on whether you intend to read or write.
  • 21. Standard IO Streams • There are three standard streams, all of which are managed by the java.lang.System class • Standard input--referenced by System.in – Used for program input, typically reads input entered by the user. • Standard output--referenced by System.out – Used for program output, typically displays information to the user. • Standard error--referenced by System.err – Used to display error messages to the user.