SlideShare a Scribd company logo
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

What's hot

Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
PhD Research Scholar
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
VINOTH R
 
Character stream classes introd .51
Character stream classes introd  .51Character stream classes introd  .51
Character stream classes introd .51myrajendra
 
Java-java virtual machine
Java-java virtual machineJava-java virtual machine
Java-java virtual machine
Surbhi Panhalkar
 
Java IO
Java IOJava IO
Java IO
UTSAB NEUPANE
 
Java applet
Java appletJava applet
Java applet
Rohan Gajre
 
The Evolution of Java
The Evolution of JavaThe Evolution of Java
The Evolution of Java
Fu Cheng
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
teach4uin
 
Packages in java
Packages in javaPackages in java
Packages in java
Elizabeth alexander
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
Ravi Kant Sahu
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
MOHIT AGARWAL
 
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Arafat Hossan
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cyclemyrajendra
 
I/O Streams
I/O StreamsI/O Streams
I/O Streams
Ravi Chythanya
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
VINOTH R
 

What's hot (20)

Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 
Character stream classes introd .51
Character stream classes introd  .51Character stream classes introd  .51
Character stream classes introd .51
 
Java-java virtual machine
Java-java virtual machineJava-java virtual machine
Java-java virtual machine
 
Java IO
Java IOJava IO
Java IO
 
Java applet
Java appletJava applet
Java applet
 
The Evolution of Java
The Evolution of JavaThe Evolution of Java
The Evolution of Java
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
 
Packages in java
Packages in javaPackages in java
Packages in java
 
OOP java
OOP javaOOP java
OOP java
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
I/O Streams
I/O StreamsI/O Streams
I/O Streams
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 

Similar to Input output streams

CHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxCHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptx
SadhilAggarwal
 
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptxChapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
noonoboom
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptx
ssuser9d7049
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
Victer Paul
 
Advanced programming ch2
Advanced programming ch2Advanced programming ch2
Advanced programming ch2
Gera Paulos
 
Input & output
Input & outputInput & output
Input & output
SAIFUR RAHMAN
 
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & OutputItp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Outputphanleson
 
Session 22 - Java IO, Serialization
Session 22 - Java IO, SerializationSession 22 - Java IO, Serialization
Session 22 - Java IO, Serialization
PawanMM
 
Java IO, Serialization
Java IO, Serialization Java IO, Serialization
Java IO, Serialization
Hitesh-Java
 
Chapter 2.1 : Data Stream
Chapter 2.1 : Data StreamChapter 2.1 : Data Stream
Chapter 2.1 : Data Stream
Ministry of Higher Education
 
CSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdfCSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdf
VithalReddy3
 
IOStream.pptx
IOStream.pptxIOStream.pptx
IOStream.pptx
HindAlmisbahi
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47myrajendra
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47myrajendra
 
05io
05io05io
Lecture 23
Lecture 23Lecture 23
Lecture 23
Debasish Pratihari
 
Java program file I/O
Java program file I/OJava program file I/O
Java program file I/O
Nem Sothea
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scanner
Arif Ullah
 

Similar to Input output streams (20)

CHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxCHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptx
 
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptxChapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptx
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
 
Advanced programming ch2
Advanced programming ch2Advanced programming ch2
Advanced programming ch2
 
Md121 streams
Md121 streamsMd121 streams
Md121 streams
 
Input & output
Input & outputInput & output
Input & output
 
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & OutputItp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
 
Session 22 - Java IO, Serialization
Session 22 - Java IO, SerializationSession 22 - Java IO, Serialization
Session 22 - Java IO, Serialization
 
Java IO, Serialization
Java IO, Serialization Java IO, Serialization
Java IO, Serialization
 
Chapter 2.1 : Data Stream
Chapter 2.1 : Data StreamChapter 2.1 : Data Stream
Chapter 2.1 : Data Stream
 
CSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdfCSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdf
 
IOStream.pptx
IOStream.pptxIOStream.pptx
IOStream.pptx
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
 
05io
05io05io
05io
 
Lecture 23
Lecture 23Lecture 23
Lecture 23
 
Java program file I/O
Java program file I/OJava program file I/O
Java program file I/O
 
Basic IO
Basic IOBasic IO
Basic IO
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scanner
 

More from Parthipan Parthi

Inheritance
Inheritance Inheritance
Inheritance
Parthipan Parthi
 
Switch statement mcq
Switch statement  mcqSwitch statement  mcq
Switch statement mcq
Parthipan Parthi
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
Parthipan Parthi
 
802.11 mac
802.11 mac802.11 mac
802.11 mac
Parthipan Parthi
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
Parthipan Parthi
 
Computer network
Computer networkComputer network
Computer network
Parthipan Parthi
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
Parthipan Parthi
 
Session 6
Session 6Session 6
Session 6
Parthipan Parthi
 
Queuing analysis
Queuing analysisQueuing analysis
Queuing analysis
Parthipan Parthi
 
WAP
WAPWAP
Alternative metrics
Alternative metricsAlternative metrics
Alternative metrics
Parthipan Parthi
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
Parthipan Parthi
 
Io stream
Io streamIo stream
Io stream
Parthipan Parthi
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
Parthipan Parthi
 
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3 REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
Parthipan Parthi
 

More from Parthipan Parthi (20)

Inheritance
Inheritance Inheritance
Inheritance
 
Switch statement mcq
Switch statement  mcqSwitch statement  mcq
Switch statement mcq
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
 
802.11 mac
802.11 mac802.11 mac
802.11 mac
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
 
Computer network
Computer networkComputer network
Computer network
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
 
Session 6
Session 6Session 6
Session 6
 
Queuing analysis
Queuing analysisQueuing analysis
Queuing analysis
 
WAP
WAPWAP
WAP
 
Alternative metrics
Alternative metricsAlternative metrics
Alternative metrics
 
Ethernet
EthernetEthernet
Ethernet
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
 
Data structures1
Data structures1Data structures1
Data structures1
 
Data structures 4
Data structures 4Data structures 4
Data structures 4
 
Data structures2
Data structures2Data structures2
Data structures2
 
Data structures 3
Data structures 3Data structures 3
Data structures 3
 
Io stream
Io streamIo stream
Io stream
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
 
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3 REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
 

Recently uploaded

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 

Recently uploaded (20)

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 

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.