SlideShare a Scribd company logo
I/O In Java Parag Shah Adaptive Software Solutions http://www.adaptivesoftware.biz http://www.adaptivelearningonline.net
Agenda Files Streams Serialization Tokenization
Overview  What should an IO system encompass? Abstractions for the following Communicating with various sources and sinks of I/O Console Files Network sockets... Doing the I/O in multiple ways Character Binary Buffered... Approach taken by Java for the IO system
Vocabulary Streams Buffers Readers Writers
Standard IO Reading from StandardInput (see Echo.java) System.in (Raw IOStream) Writing to Standard Output System.out (PrintStream) Standard Error System.err (PrintStream) Redirecting standard IO  [see: Redirecting.java]
A Simple Example System.out.println(); System is a class out is a static attribute of system out is of type PrintStream
A Simple Example contd. System.in.read(); BufferedReader br = new BufferedInputStream(new InputStreamReader(System.in)); System is a class in is a static attribute of system in is of type InputStream InputStreamReader converts an InputStream to the Reader hierarchy BufferedReader adds buffering and line reading capabilities to the Reader
Files & Directories The File class is an abstract represention of file and directory pathnames It does NOT represent a file see  FileExample.java RandomAccessFile  does represent a file Can read or write at arbitrary locations
Streams What are Streams? Arbitrary data source/destination Details of the device is abstracted InputStream Data input source Abstract  class java.io.InputStream OutputStream Data output destination Abstract  class java.io.OutputStream
InputStream Various sources of data Array of bytes String object File Pipe
InputStream See  [StreamExample.java]
OutputStream Data Sinks ByteArray File Pipe
OutputStream See [StreamExample.java]
FilterInputStream Used to format/filter data being read from an InputStream Types of FilterInputStream DataInputStream BufferedInputStream LineNumberInputStream PushbackInputStream
FilterOutputStream Used to write formatted/filtered data to an OutputStream Types of FilterOutputStream DataOutputStream PrintStream BufferedOutputStream
Readers & Writers Purpose of Readers & Writers Input/Output Stream are for byte based I/O Readers for unicode based char I/O Modifying stream behaviour FilterReader FilterWriter (abstract class with no subclasses)
The Reader Hierarchy The Reader Hierarchy
The Writer Hierarchy The Writer Hierarchy
IO Best Practices Best Practice Use Readers / Writers for character IO Use Input/OutputStream for byte based IO For reading/writing data in a portable manner use DataInput(Output)Stream Use buffering Always close the streams
Object Serialization - 1 What is serialization When do we need serialization
Object Serialization - 2 Serializing objects ObjectOutputStream Deserializing objects ObjectInputStream Remember no constructors are called see  [SerializationExample.java]
Object Serialization - 3 Controlling serialization The Serializable interface The  transient  keyword The Externalizable interface
Tokenizing What are tokens? StringTokenizer StreamTokenizer
String Tokenizer Tokenizes a String We must define delimiting characters Throws an Exception if we go beyond the String size. See  [StringTokenizingExample.java] It is recommended to use the split() method in String See  [StringSplitExample.java]
Stream Tokenizer Tokenizes an input stream Parsing process is controlled by a table and flags Each byte read from the input stream is regarded as a character in the range '\u0000' through '\u00FF'
Stream Tokenizer The character value is used to look up five possible attributes of the character White space Alphabetic Numeric String quote Comment character Each character can have zero or more of these attributes
Stream Tokenizer Each tokenizer has four flags :- Whether line terminators are to be returned as tokens or treated as white space that merely separates tokens. Whether C-style comments are to be recognized and skipped. Whether C++-style comments are to be recognized and skipped. Whether the characters of identifiers are converted to lowercase.
Using Stream Tokenizer Create an instance of StreamTokenizer Set up tables and flags Loop through the stream calling nextToken until a TT_EOF is returned. See  [StreamTokenizingExample.java]
Summary Streams Types of Input & Output streams The decorator design pattern The need for so many stream classes Serialization Tokenizing
Where to Get More Information Thinking In Java By Bruce Eckel Sun Java Trail http://java.sun.com/docs/books/tutorial/essential/io/index.html

More Related Content

PPT
Java stream
Arati Gadgil
 
PPTX
Understanding java streams
Shahjahan Samoon
 
PPTX
Java Input Output (java.io.*)
Om Ganesh
 
PPT
Java Streams
M Vishnuvardhan Reddy
 
PDF
Java IO
UTSAB NEUPANE
 
PPTX
L21 io streams
teach4uin
 
PDF
Java I/o streams
Hamid Ghorbani
 
PDF
32.java input-output
santosh mishra
 
Java stream
Arati Gadgil
 
Understanding java streams
Shahjahan Samoon
 
Java Input Output (java.io.*)
Om Ganesh
 
Java Streams
M Vishnuvardhan Reddy
 
Java IO
UTSAB NEUPANE
 
L21 io streams
teach4uin
 
Java I/o streams
Hamid Ghorbani
 
32.java input-output
santosh mishra
 

What's hot (20)

PPTX
Handling I/O in Java
Hiranya Jayathilaka
 
PDF
Java Course 8: I/O, Files and Streams
Anton Keks
 
PPT
Input output streams
Parthipan Parthi
 
PDF
Java I/O
Jussi Pohjolainen
 
PDF
java.io - streams and files
Marcello Thiry
 
PPS
Files & IO in Java
CIB Egypt
 
PDF
input/ output in java
sharma230399
 
PPT
Java IO Package and Streams
babak danyal
 
PDF
Files in java
Muthukumaran Subramanian
 
PPT
Byte stream classes.49
myrajendra
 
PPT
Various io stream classes .47
myrajendra
 
PDF
Javaiostream
Tien Nguyen
 
PPT
IO and serialization
backdoor
 
PPTX
Java file
sonnetdp
 
PPT
Character stream classes introd .51
myrajendra
 
PPT
Chapter 12 - File Input and Output
Eduardo Bergavera
 
DOCX
Oodp mod4
cs19club
 
PPTX
Java I/O
Jayant Dalvi
 
PPTX
Io streams
Elizabeth alexander
 
PPT
File Input & Output
PRN USM
 
Handling I/O in Java
Hiranya Jayathilaka
 
Java Course 8: I/O, Files and Streams
Anton Keks
 
Input output streams
Parthipan Parthi
 
java.io - streams and files
Marcello Thiry
 
Files & IO in Java
CIB Egypt
 
input/ output in java
sharma230399
 
Java IO Package and Streams
babak danyal
 
Byte stream classes.49
myrajendra
 
Various io stream classes .47
myrajendra
 
Javaiostream
Tien Nguyen
 
IO and serialization
backdoor
 
Java file
sonnetdp
 
Character stream classes introd .51
myrajendra
 
Chapter 12 - File Input and Output
Eduardo Bergavera
 
Oodp mod4
cs19club
 
Java I/O
Jayant Dalvi
 
File Input & Output
PRN USM
 
Ad

Viewers also liked (20)

PDF
java.io - fluxos (streams) e arquivos
Marcello Thiry
 
PPTX
Java: Manipulação de Arquivos
Arthur Emanuel
 
PPTX
Java nio ( new io )
Jemin Patel
 
PPT
Ficheiros em JAVA
Pedro De Almeida
 
PDF
My History
santosh mishra
 
PDF
Design Pattern From Java To Ruby
yelogic
 
PPTX
Java Multi Thead Programming
Nishant Mevawala
 
PPTX
Multi-threaded Programming in JAVA
Vikram Kalyani
 
PPT
Threads in Java
Gaurav Aggarwal
 
PPT
Apostila 8 sistema de arquivos
Paulo Fonseca
 
PDF
Programming with Threads in Java
koji lin
 
PDF
Threads concept in java
Muthukumaran Subramanian
 
PPT
Threads in java
mukesh singh
 
PPT
Java applets
Khan Mac-arther
 
PPTX
Applet java
Jorge Luis Tinoco
 
PDF
27 applet programming
Ravindra Rathore
 
ODP
Exception Handling In Java
parag
 
PPTX
Multithread Programing in Java
M. Raihan
 
ODP
Multithreading In Java
parag
 
PPS
Java applets
Srinath Dhayalamoorthy
 
java.io - fluxos (streams) e arquivos
Marcello Thiry
 
Java: Manipulação de Arquivos
Arthur Emanuel
 
Java nio ( new io )
Jemin Patel
 
Ficheiros em JAVA
Pedro De Almeida
 
My History
santosh mishra
 
Design Pattern From Java To Ruby
yelogic
 
Java Multi Thead Programming
Nishant Mevawala
 
Multi-threaded Programming in JAVA
Vikram Kalyani
 
Threads in Java
Gaurav Aggarwal
 
Apostila 8 sistema de arquivos
Paulo Fonseca
 
Programming with Threads in Java
koji lin
 
Threads concept in java
Muthukumaran Subramanian
 
Threads in java
mukesh singh
 
Java applets
Khan Mac-arther
 
Applet java
Jorge Luis Tinoco
 
27 applet programming
Ravindra Rathore
 
Exception Handling In Java
parag
 
Multithread Programing in Java
M. Raihan
 
Multithreading In Java
parag
 
Ad

Similar to IO In Java (20)

PPT
Md121 streams
Rakesh Madugula
 
PPT
Using Input Output
raksharao
 
PPT
Stream Based Input Output
Bharat17485
 
PDF
11_Str11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.eams.pdf
hungvidien123
 
PPTX
Javaiostream
Manav Prasad
 
PDF
Java IO Stream, the introduction to Streams
ranganadh6
 
PDF
Basic IO
Ravi_Kant_Sahu
 
PPTX
IOStream.pptx
HindAlmisbahi
 
PPT
Java development development Files lectur6.ppt
rafeakrafeak
 
DOCX
Unit IV Notes.docx
GayathriRHICETCSESTA
 
PPTX
I/O Streams
Ravi Chythanya
 
PDF
UNIT4-IO,Generics,String Handling.pdf Notes
SakkaravarthiS1
 
PDF
Monhocvecaujahetvagiuplaptunhhayhonha.pdf
cuchuoi83ne
 
PDF
inputoutputstreams-140612032817-phpapp02.pdf
hemanth248901
 
PPTX
JAVA (UNIT 3)
Dr. SURBHI SAROHA
 
DOC
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
uthayashangar1
 
PPT
Itp 120 Chapt 19 2009 Binary Input & Output
phanleson
 
PPTX
Input output files in java
Kavitha713564
 
PDF
IOstreams hgjhsgfdjyggckhgckhjxfhbuvobunciu
akinbhattarai1
 
PPTX
Stream In Java.pptx
ssuser9d7049
 
Md121 streams
Rakesh Madugula
 
Using Input Output
raksharao
 
Stream Based Input Output
Bharat17485
 
11_Str11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.eams.pdf
hungvidien123
 
Javaiostream
Manav Prasad
 
Java IO Stream, the introduction to Streams
ranganadh6
 
Basic IO
Ravi_Kant_Sahu
 
IOStream.pptx
HindAlmisbahi
 
Java development development Files lectur6.ppt
rafeakrafeak
 
Unit IV Notes.docx
GayathriRHICETCSESTA
 
I/O Streams
Ravi Chythanya
 
UNIT4-IO,Generics,String Handling.pdf Notes
SakkaravarthiS1
 
Monhocvecaujahetvagiuplaptunhhayhonha.pdf
cuchuoi83ne
 
inputoutputstreams-140612032817-phpapp02.pdf
hemanth248901
 
JAVA (UNIT 3)
Dr. SURBHI SAROHA
 
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
uthayashangar1
 
Itp 120 Chapt 19 2009 Binary Input & Output
phanleson
 
Input output files in java
Kavitha713564
 
IOstreams hgjhsgfdjyggckhgckhjxfhbuvobunciu
akinbhattarai1
 
Stream In Java.pptx
ssuser9d7049
 

More from parag (16)

ODP
Application Development Using Java - DIYComputerScience Course
parag
 
ODP
Version Control With svn Setting The Stage
parag
 
ODP
Effective exceptions
parag
 
ODP
Data structures
parag
 
ODP
Building Internet Reputation
parag
 
ODP
General method best_practices
parag
 
ODP
Make defensive copies
parag
 
ODP
Check methods params_for_validity
parag
 
ODP
Double checkedlockingjavasingletons
parag
 
ODP
Uml
parag
 
PDF
Internet And New Media For Teaching
parag
 
ODP
Java Collections
parag
 
ODP
Blogging and The Learning Professional
parag
 
PPT
Inner Classes
parag
 
PPT
Interfaces In Java
parag
 
PPT
Goals Of Software Design - The main goals
parag
 
Application Development Using Java - DIYComputerScience Course
parag
 
Version Control With svn Setting The Stage
parag
 
Effective exceptions
parag
 
Data structures
parag
 
Building Internet Reputation
parag
 
General method best_practices
parag
 
Make defensive copies
parag
 
Check methods params_for_validity
parag
 
Double checkedlockingjavasingletons
parag
 
Uml
parag
 
Internet And New Media For Teaching
parag
 
Java Collections
parag
 
Blogging and The Learning Professional
parag
 
Inner Classes
parag
 
Interfaces In Java
parag
 
Goals Of Software Design - The main goals
parag
 

Recently uploaded (20)

PDF
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
AVTRON Technologies LLC
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PDF
Make GenAI investments go further with the Dell AI Factory - Infographic
Principled Technologies
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
AVTRON Technologies LLC
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
Make GenAI investments go further with the Dell AI Factory - Infographic
Principled Technologies
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
This slide provides an overview Technology
mineshkharadi333
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 

IO In Java

  • 1. I/O In Java Parag Shah Adaptive Software Solutions http://www.adaptivesoftware.biz http://www.adaptivelearningonline.net
  • 2. Agenda Files Streams Serialization Tokenization
  • 3. Overview What should an IO system encompass? Abstractions for the following Communicating with various sources and sinks of I/O Console Files Network sockets... Doing the I/O in multiple ways Character Binary Buffered... Approach taken by Java for the IO system
  • 4. Vocabulary Streams Buffers Readers Writers
  • 5. Standard IO Reading from StandardInput (see Echo.java) System.in (Raw IOStream) Writing to Standard Output System.out (PrintStream) Standard Error System.err (PrintStream) Redirecting standard IO [see: Redirecting.java]
  • 6. A Simple Example System.out.println(); System is a class out is a static attribute of system out is of type PrintStream
  • 7. A Simple Example contd. System.in.read(); BufferedReader br = new BufferedInputStream(new InputStreamReader(System.in)); System is a class in is a static attribute of system in is of type InputStream InputStreamReader converts an InputStream to the Reader hierarchy BufferedReader adds buffering and line reading capabilities to the Reader
  • 8. Files & Directories The File class is an abstract represention of file and directory pathnames It does NOT represent a file see FileExample.java RandomAccessFile does represent a file Can read or write at arbitrary locations
  • 9. Streams What are Streams? Arbitrary data source/destination Details of the device is abstracted InputStream Data input source Abstract class java.io.InputStream OutputStream Data output destination Abstract class java.io.OutputStream
  • 10. InputStream Various sources of data Array of bytes String object File Pipe
  • 11. InputStream See [StreamExample.java]
  • 12. OutputStream Data Sinks ByteArray File Pipe
  • 14. FilterInputStream Used to format/filter data being read from an InputStream Types of FilterInputStream DataInputStream BufferedInputStream LineNumberInputStream PushbackInputStream
  • 15. FilterOutputStream Used to write formatted/filtered data to an OutputStream Types of FilterOutputStream DataOutputStream PrintStream BufferedOutputStream
  • 16. Readers & Writers Purpose of Readers & Writers Input/Output Stream are for byte based I/O Readers for unicode based char I/O Modifying stream behaviour FilterReader FilterWriter (abstract class with no subclasses)
  • 17. The Reader Hierarchy The Reader Hierarchy
  • 18. The Writer Hierarchy The Writer Hierarchy
  • 19. IO Best Practices Best Practice Use Readers / Writers for character IO Use Input/OutputStream for byte based IO For reading/writing data in a portable manner use DataInput(Output)Stream Use buffering Always close the streams
  • 20. Object Serialization - 1 What is serialization When do we need serialization
  • 21. Object Serialization - 2 Serializing objects ObjectOutputStream Deserializing objects ObjectInputStream Remember no constructors are called see [SerializationExample.java]
  • 22. Object Serialization - 3 Controlling serialization The Serializable interface The transient keyword The Externalizable interface
  • 23. Tokenizing What are tokens? StringTokenizer StreamTokenizer
  • 24. String Tokenizer Tokenizes a String We must define delimiting characters Throws an Exception if we go beyond the String size. See [StringTokenizingExample.java] It is recommended to use the split() method in String See [StringSplitExample.java]
  • 25. Stream Tokenizer Tokenizes an input stream Parsing process is controlled by a table and flags Each byte read from the input stream is regarded as a character in the range '\u0000' through '\u00FF'
  • 26. Stream Tokenizer The character value is used to look up five possible attributes of the character White space Alphabetic Numeric String quote Comment character Each character can have zero or more of these attributes
  • 27. Stream Tokenizer Each tokenizer has four flags :- Whether line terminators are to be returned as tokens or treated as white space that merely separates tokens. Whether C-style comments are to be recognized and skipped. Whether C++-style comments are to be recognized and skipped. Whether the characters of identifiers are converted to lowercase.
  • 28. Using Stream Tokenizer Create an instance of StreamTokenizer Set up tables and flags Loop through the stream calling nextToken until a TT_EOF is returned. See [StreamTokenizingExample.java]
  • 29. Summary Streams Types of Input & Output streams The decorator design pattern The need for so many stream classes Serialization Tokenizing
  • 30. Where to Get More Information Thinking In Java By Bruce Eckel Sun Java Trail http://java.sun.com/docs/books/tutorial/essential/io/index.html