SlideShare a Scribd company logo
java.io Package
Sujit Kumar
Zenolocity LLC
Copyright 2012-2024 @
java.io Package
• The java.io package contains a fairly large number
of classes that deal with Java input & output.
Most of the classes consist of:
• Byte streams : that are subclasses of the abstract
classes InputStream or OutputStream
• Character streams : that are subclasses of the
abstract classes Reader and Writer
• The methods for reading & writing data from
byte streams and character streams are similar.
java.io Package (contd…)
• The Reader and Writer classes read and write
16-bit Unicode characters.
• The InputStream and OutputStream classes
read and write 8-bit bytes respectively.
• Derived classes of the above 4 abstract classes
add additional responsibilities using the
Decorator pattern.
How to choose the correct
implementation (derived class)?
•
•
•
•

What is your format: text or binary ?
Do you want random access to a file ?
Are you using objects or non-objects ?
What are your sources and sinks of data (like
sockets, files, strings or array of characters) ?
• Do you need to use filtering techniques like
buffering, checksumming ?
Byte Stream Abstract Classes
InputStream — byte reader

•
•
•
•

read() a single byte or an array of bytes
skip() bytes
mark() and reset() position
close() the stream (always in finally block)

OutputStream —byte writer
• write() a single byte or an array of bytes
• flush() the stream (in case it is buffered)
• close() the stream (always in finally block)
Character Stream Abstract Classes
Reader — character reader

•
•
•
•

read() a single char or into a char array
skip() chars
mark() and reset() position
close() the stream (always in finally block)

Writer — character writer
• write() a single char or from a char array
• flush() the stream (in case it is buffered)
• close() the stream (always in finally block)
Byte Stream Concrete classes
•
•
•
•
•
•
•
•

FileInputStream, FileOutputStream
BufferedInputStream, BufferedOutputStream
ByteArrayInputStream, ByteArrayOutputStream
DataInputStream, DataOutputStream
FilterInputStream, FilterOutputStream
ObjectInputStream, ObjectOutputStream
PipedInputStream, PipedOutputStream
LineNumberInputStream

• PrintStream
Character Stream Concrete classes
•
•
•
•
•
•
•
•

FileReader, FileWriter
BufferedReader, BufferedWriter
CharArrayReader, CharArrayWriter
InputStreamReader, InputStreamWriter
FilterReader, FilterWriter
ObjectReader, ObjectWriter
PipedReader, PipedWriter
StringReader, StringWriter

• LineNumberReader
• PrintWriter
Applying the Decorator Pattern
• Example: Read each line from a file
• BufferedReader => InputStreamReader =>
FileInputStream
• Wrap an InputStreamReader over a
FileInputStream.
• Then, wrap a BufferedReader over the
InputStreamReader.
Applying the Decorator Pattern
(contd…)
• BufferedReader => Reads text from a characterinput stream, buffering characters so as to
provide for the efficient reading of characters,
arrays, and lines.
• FileInputStream => obtains input bytes from a file
in a file system.
• InputStreamReader => bridge from byte streams
to character streams. It reads bytes and decodes
them into characters using a specified charset.
Exception Handling
• The constructors and methods of I/O classes can
throw a checked exception.
• The base class for I/O exceptions is
java.io.IOException. Some methods can throw a
subclass of IOException.
For example, the constructors of FileInputStream, FileOutputStream and
FileReader can throw FileNotFoundException.

• The call to close() should always occur in a finally
block (ensures that the I/O channel is closed
properly even if an exception occurs).

More Related Content

What's hot (19)

Input output streams
Input output streamsInput output streams
Input output streams
Parthipan Parthi
 
IO In Java
IO In JavaIO In Java
IO In Java
parag
 
Character stream classes .52
Character stream classes .52Character stream classes .52
Character stream classes .52
myrajendra
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
teach4uin
 
Java Streams
Java StreamsJava Streams
Java Streams
M Vishnuvardhan Reddy
 
Java stereams
Java stereamsJava stereams
Java stereams
Jernej Virag
 
Javaiostream
JavaiostreamJavaiostream
Javaiostream
Manav Prasad
 
File Handling in Java Oop presentation
File Handling in Java Oop presentationFile Handling in Java Oop presentation
File Handling in Java Oop presentation
Azeemaj101
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
JayasankarPR2
 
Java I/O
Java I/OJava I/O
Java I/O
DeeptiJava
 
IO and serialization
IO and serializationIO and serialization
IO and serialization
backdoor
 
Java program file I/O
Java program file I/OJava program file I/O
Java program file I/O
Nem Sothea
 
An Introduction To Python - Files, Part 1
An Introduction To Python - Files, Part 1An Introduction To Python - Files, Part 1
An Introduction To Python - Files, Part 1
Blue Elephant Consulting
 
Jedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io StreamsJedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io Streams
Don Bosco BSIT
 
Input & output
Input & outputInput & output
Input & output
SAIFUR RAHMAN
 
30csharp
30csharp30csharp
30csharp
Sireesh K
 
Javaiostream
JavaiostreamJavaiostream
Javaiostream
Tien Nguyen
 
9 Inputs & Outputs
9 Inputs & Outputs9 Inputs & Outputs
9 Inputs & Outputs
Deepak Hagadur Bheemaraju
 
32sql server
32sql server32sql server
32sql server
Sireesh K
 
IO In Java
IO In JavaIO In Java
IO In Java
parag
 
Character stream classes .52
Character stream classes .52Character stream classes .52
Character stream classes .52
myrajendra
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
teach4uin
 
File Handling in Java Oop presentation
File Handling in Java Oop presentationFile Handling in Java Oop presentation
File Handling in Java Oop presentation
Azeemaj101
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
JayasankarPR2
 
IO and serialization
IO and serializationIO and serialization
IO and serialization
backdoor
 
Java program file I/O
Java program file I/OJava program file I/O
Java program file I/O
Nem Sothea
 
Jedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io StreamsJedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io Streams
Don Bosco BSIT
 
32sql server
32sql server32sql server
32sql server
Sireesh K
 

Similar to Java input output package (20)

Iostreams
IostreamsIostreams
Iostreams
aptechsravan
 
Using Input Output
Using Input OutputUsing Input Output
Using Input Output
raksharao
 
Java I/O
Java I/OJava I/O
Java I/O
Jayant Dalvi
 
UNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf NotesUNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf Notes
SakkaravarthiS1
 
Monhocvecaujahetvagiuplaptunhhayhonha.pdf
Monhocvecaujahetvagiuplaptunhhayhonha.pdfMonhocvecaujahetvagiuplaptunhhayhonha.pdf
Monhocvecaujahetvagiuplaptunhhayhonha.pdf
cuchuoi83ne
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptx
ssuser9d7049
 
Java development development Files lectur6.ppt
Java development development Files lectur6.pptJava development development Files lectur6.ppt
Java development development Files lectur6.ppt
rafeakrafeak
 
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
uthayashangar1
 
I/O Streams
I/O StreamsI/O Streams
I/O Streams
Ravi Chythanya
 
IOstreams hgjhsgfdjyggckhgckhjxfhbuvobunciu
IOstreams hgjhsgfdjyggckhgckhjxfhbuvobunciuIOstreams hgjhsgfdjyggckhgckhjxfhbuvobunciu
IOstreams hgjhsgfdjyggckhgckhjxfhbuvobunciu
akinbhattarai1
 
Java Input and Output
Java Input and OutputJava Input and Output
Java Input and Output
Ducat India
 
IOStream.pptx
IOStream.pptxIOStream.pptx
IOStream.pptx
HindAlmisbahi
 
Java Day-6
Java Day-6Java Day-6
Java Day-6
People Strategists
 
IO Programming.pptx all informatiyon ppt
IO Programming.pptx all informatiyon pptIO Programming.pptx all informatiyon ppt
IO Programming.pptx all informatiyon ppt
nandinimakwana22cse
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
Kavitha713564
 
Io streams
Io streamsIo streams
Io streams
Elizabeth alexander
 
Unit IV Notes.docx
Unit IV Notes.docxUnit IV Notes.docx
Unit IV Notes.docx
GayathriRHICETCSESTA
 
11_Str11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.eams.pdf
11_Str11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.eams.pdf11_Str11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.eams.pdf
11_Str11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.eams.pdf
hungvidien123
 
Programming language JAVA Input output opearations
Programming language JAVA Input output opearationsProgramming language JAVA Input output opearations
Programming language JAVA Input output opearations
2025183005
 
Files & IO in Java
Files & IO in JavaFiles & IO in Java
Files & IO in Java
CIB Egypt
 
Using Input Output
Using Input OutputUsing Input Output
Using Input Output
raksharao
 
UNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf NotesUNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf Notes
SakkaravarthiS1
 
Monhocvecaujahetvagiuplaptunhhayhonha.pdf
Monhocvecaujahetvagiuplaptunhhayhonha.pdfMonhocvecaujahetvagiuplaptunhhayhonha.pdf
Monhocvecaujahetvagiuplaptunhhayhonha.pdf
cuchuoi83ne
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptx
ssuser9d7049
 
Java development development Files lectur6.ppt
Java development development Files lectur6.pptJava development development Files lectur6.ppt
Java development development Files lectur6.ppt
rafeakrafeak
 
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
uthayashangar1
 
IOstreams hgjhsgfdjyggckhgckhjxfhbuvobunciu
IOstreams hgjhsgfdjyggckhgckhjxfhbuvobunciuIOstreams hgjhsgfdjyggckhgckhjxfhbuvobunciu
IOstreams hgjhsgfdjyggckhgckhjxfhbuvobunciu
akinbhattarai1
 
Java Input and Output
Java Input and OutputJava Input and Output
Java Input and Output
Ducat India
 
IO Programming.pptx all informatiyon ppt
IO Programming.pptx all informatiyon pptIO Programming.pptx all informatiyon ppt
IO Programming.pptx all informatiyon ppt
nandinimakwana22cse
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
Kavitha713564
 
11_Str11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.eams.pdf
11_Str11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.eams.pdf11_Str11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.eams.pdf
11_Str11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.eams.pdf
hungvidien123
 
Programming language JAVA Input output opearations
Programming language JAVA Input output opearationsProgramming language JAVA Input output opearations
Programming language JAVA Input output opearations
2025183005
 
Files & IO in Java
Files & IO in JavaFiles & IO in Java
Files & IO in Java
CIB Egypt
 
Ad

More from Sujit Kumar (20)

Introduction to OOP with java
Introduction to OOP with javaIntroduction to OOP with java
Introduction to OOP with java
Sujit Kumar
 
SFDC Database Basics
SFDC Database BasicsSFDC Database Basics
SFDC Database Basics
Sujit Kumar
 
SFDC Database Security
SFDC Database SecuritySFDC Database Security
SFDC Database Security
Sujit Kumar
 
SFDC Social Applications
SFDC Social ApplicationsSFDC Social Applications
SFDC Social Applications
Sujit Kumar
 
SFDC Other Platform Features
SFDC Other Platform FeaturesSFDC Other Platform Features
SFDC Other Platform Features
Sujit Kumar
 
SFDC Outbound Integrations
SFDC Outbound IntegrationsSFDC Outbound Integrations
SFDC Outbound Integrations
Sujit Kumar
 
SFDC Inbound Integrations
SFDC Inbound IntegrationsSFDC Inbound Integrations
SFDC Inbound Integrations
Sujit Kumar
 
SFDC UI - Advanced Visualforce
SFDC UI - Advanced VisualforceSFDC UI - Advanced Visualforce
SFDC UI - Advanced Visualforce
Sujit Kumar
 
SFDC UI - Introduction to Visualforce
SFDC UI -  Introduction to VisualforceSFDC UI -  Introduction to Visualforce
SFDC UI - Introduction to Visualforce
Sujit Kumar
 
SFDC Deployments
SFDC DeploymentsSFDC Deployments
SFDC Deployments
Sujit Kumar
 
SFDC Batch Apex
SFDC Batch ApexSFDC Batch Apex
SFDC Batch Apex
Sujit Kumar
 
SFDC Data Loader
SFDC Data LoaderSFDC Data Loader
SFDC Data Loader
Sujit Kumar
 
SFDC Advanced Apex
SFDC Advanced Apex SFDC Advanced Apex
SFDC Advanced Apex
Sujit Kumar
 
SFDC Introduction to Apex
SFDC Introduction to ApexSFDC Introduction to Apex
SFDC Introduction to Apex
Sujit Kumar
 
SFDC Database Additional Features
SFDC Database Additional FeaturesSFDC Database Additional Features
SFDC Database Additional Features
Sujit Kumar
 
Introduction to SalesForce
Introduction to SalesForceIntroduction to SalesForce
Introduction to SalesForce
Sujit Kumar
 
More about java strings - Immutability and String Pool
More about java strings - Immutability and String PoolMore about java strings - Immutability and String Pool
More about java strings - Immutability and String Pool
Sujit Kumar
 
Hibernate First and Second level caches
Hibernate First and Second level cachesHibernate First and Second level caches
Hibernate First and Second level caches
Sujit Kumar
 
Java equals hashCode Contract
Java equals hashCode ContractJava equals hashCode Contract
Java equals hashCode Contract
Sujit Kumar
 
Java Comparable and Comparator
Java Comparable and ComparatorJava Comparable and Comparator
Java Comparable and Comparator
Sujit Kumar
 
Introduction to OOP with java
Introduction to OOP with javaIntroduction to OOP with java
Introduction to OOP with java
Sujit Kumar
 
SFDC Database Basics
SFDC Database BasicsSFDC Database Basics
SFDC Database Basics
Sujit Kumar
 
SFDC Database Security
SFDC Database SecuritySFDC Database Security
SFDC Database Security
Sujit Kumar
 
SFDC Social Applications
SFDC Social ApplicationsSFDC Social Applications
SFDC Social Applications
Sujit Kumar
 
SFDC Other Platform Features
SFDC Other Platform FeaturesSFDC Other Platform Features
SFDC Other Platform Features
Sujit Kumar
 
SFDC Outbound Integrations
SFDC Outbound IntegrationsSFDC Outbound Integrations
SFDC Outbound Integrations
Sujit Kumar
 
SFDC Inbound Integrations
SFDC Inbound IntegrationsSFDC Inbound Integrations
SFDC Inbound Integrations
Sujit Kumar
 
SFDC UI - Advanced Visualforce
SFDC UI - Advanced VisualforceSFDC UI - Advanced Visualforce
SFDC UI - Advanced Visualforce
Sujit Kumar
 
SFDC UI - Introduction to Visualforce
SFDC UI -  Introduction to VisualforceSFDC UI -  Introduction to Visualforce
SFDC UI - Introduction to Visualforce
Sujit Kumar
 
SFDC Deployments
SFDC DeploymentsSFDC Deployments
SFDC Deployments
Sujit Kumar
 
SFDC Data Loader
SFDC Data LoaderSFDC Data Loader
SFDC Data Loader
Sujit Kumar
 
SFDC Advanced Apex
SFDC Advanced Apex SFDC Advanced Apex
SFDC Advanced Apex
Sujit Kumar
 
SFDC Introduction to Apex
SFDC Introduction to ApexSFDC Introduction to Apex
SFDC Introduction to Apex
Sujit Kumar
 
SFDC Database Additional Features
SFDC Database Additional FeaturesSFDC Database Additional Features
SFDC Database Additional Features
Sujit Kumar
 
Introduction to SalesForce
Introduction to SalesForceIntroduction to SalesForce
Introduction to SalesForce
Sujit Kumar
 
More about java strings - Immutability and String Pool
More about java strings - Immutability and String PoolMore about java strings - Immutability and String Pool
More about java strings - Immutability and String Pool
Sujit Kumar
 
Hibernate First and Second level caches
Hibernate First and Second level cachesHibernate First and Second level caches
Hibernate First and Second level caches
Sujit Kumar
 
Java equals hashCode Contract
Java equals hashCode ContractJava equals hashCode Contract
Java equals hashCode Contract
Sujit Kumar
 
Java Comparable and Comparator
Java Comparable and ComparatorJava Comparable and Comparator
Java Comparable and Comparator
Sujit Kumar
 
Ad

Recently uploaded (20)

“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
Edge AI and Vision Alliance
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
Edge AI and Vision Alliance
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 

Java input output package

  • 1. java.io Package Sujit Kumar Zenolocity LLC Copyright 2012-2024 @
  • 2. java.io Package • The java.io package contains a fairly large number of classes that deal with Java input & output. Most of the classes consist of: • Byte streams : that are subclasses of the abstract classes InputStream or OutputStream • Character streams : that are subclasses of the abstract classes Reader and Writer • The methods for reading & writing data from byte streams and character streams are similar.
  • 3. java.io Package (contd…) • The Reader and Writer classes read and write 16-bit Unicode characters. • The InputStream and OutputStream classes read and write 8-bit bytes respectively. • Derived classes of the above 4 abstract classes add additional responsibilities using the Decorator pattern.
  • 4. How to choose the correct implementation (derived class)? • • • • What is your format: text or binary ? Do you want random access to a file ? Are you using objects or non-objects ? What are your sources and sinks of data (like sockets, files, strings or array of characters) ? • Do you need to use filtering techniques like buffering, checksumming ?
  • 5. Byte Stream Abstract Classes InputStream — byte reader • • • • read() a single byte or an array of bytes skip() bytes mark() and reset() position close() the stream (always in finally block) OutputStream —byte writer • write() a single byte or an array of bytes • flush() the stream (in case it is buffered) • close() the stream (always in finally block)
  • 6. Character Stream Abstract Classes Reader — character reader • • • • read() a single char or into a char array skip() chars mark() and reset() position close() the stream (always in finally block) Writer — character writer • write() a single char or from a char array • flush() the stream (in case it is buffered) • close() the stream (always in finally block)
  • 7. Byte Stream Concrete classes • • • • • • • • FileInputStream, FileOutputStream BufferedInputStream, BufferedOutputStream ByteArrayInputStream, ByteArrayOutputStream DataInputStream, DataOutputStream FilterInputStream, FilterOutputStream ObjectInputStream, ObjectOutputStream PipedInputStream, PipedOutputStream LineNumberInputStream • PrintStream
  • 8. Character Stream Concrete classes • • • • • • • • FileReader, FileWriter BufferedReader, BufferedWriter CharArrayReader, CharArrayWriter InputStreamReader, InputStreamWriter FilterReader, FilterWriter ObjectReader, ObjectWriter PipedReader, PipedWriter StringReader, StringWriter • LineNumberReader • PrintWriter
  • 9. Applying the Decorator Pattern • Example: Read each line from a file • BufferedReader => InputStreamReader => FileInputStream • Wrap an InputStreamReader over a FileInputStream. • Then, wrap a BufferedReader over the InputStreamReader.
  • 10. Applying the Decorator Pattern (contd…) • BufferedReader => Reads text from a characterinput stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines. • FileInputStream => obtains input bytes from a file in a file system. • InputStreamReader => bridge from byte streams to character streams. It reads bytes and decodes them into characters using a specified charset.
  • 11. Exception Handling • The constructors and methods of I/O classes can throw a checked exception. • The base class for I/O exceptions is java.io.IOException. Some methods can throw a subclass of IOException. For example, the constructors of FileInputStream, FileOutputStream and FileReader can throw FileNotFoundException. • The call to close() should always occur in a finally block (ensures that the I/O channel is closed properly even if an exception occurs).