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

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
 

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)

PPTX
I/O Streams
Ravi Chythanya
 
PDF
UNIT4-IO,Generics,String Handling.pdf Notes
SakkaravarthiS1
 
PPTX
Computer science input and output BASICS.pptx
RathanMB
 
PPT
Md121 streams
Rakesh Madugula
 
PPTX
Stream In Java.pptx
ssuser9d7049
 
PPT
Using Input Output
raksharao
 
PPTX
Java Input and Output
Ducat India
 
DOCX
Unit IV Notes.docx
GayathriRHICETCSESTA
 
PPT
Stream Based Input Output
Bharat17485
 
DOC
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
uthayashangar1
 
PPT
Io Streams
phanleson
 
PPT
Java development development Files lectur6.ppt
rafeakrafeak
 
PPT
Itp 120 Chapt 19 2009 Binary Input & Output
phanleson
 
PPTX
CHAPTER 5 mechanical engineeringasaaa.pptx
SadhilAggarwal
 
PDF
Nhap xuat trong java
tuhn
 
PDF
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
DOCX
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
PPTX
File Input and output.pptx
cherryreddygannu
 
PDF
Java IO Stream, the introduction to Streams
ranganadh6
 
PPTX
JAVA (UNIT 3)
Dr. SURBHI SAROHA
 
I/O Streams
Ravi Chythanya
 
UNIT4-IO,Generics,String Handling.pdf Notes
SakkaravarthiS1
 
Computer science input and output BASICS.pptx
RathanMB
 
Md121 streams
Rakesh Madugula
 
Stream In Java.pptx
ssuser9d7049
 
Using Input Output
raksharao
 
Java Input and Output
Ducat India
 
Unit IV Notes.docx
GayathriRHICETCSESTA
 
Stream Based Input Output
Bharat17485
 
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
uthayashangar1
 
Io Streams
phanleson
 
Java development development Files lectur6.ppt
rafeakrafeak
 
Itp 120 Chapt 19 2009 Binary Input & Output
phanleson
 
CHAPTER 5 mechanical engineeringasaaa.pptx
SadhilAggarwal
 
Nhap xuat trong java
tuhn
 
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
File Input and output.pptx
cherryreddygannu
 
Java IO Stream, the introduction to Streams
ranganadh6
 
JAVA (UNIT 3)
Dr. SURBHI SAROHA
 
Ad

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
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
PDF
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
PDF
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PPTX
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
Top Managed Service Providers in Los Angeles
Captain IT
 
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
July Patch Tuesday
Ivanti
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 

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