1. Data Stream
“Stream is a process to read a data from 1 resource or send
a data to another location.”
2. What is Stream
• All data in JAVA platform was read and write by Stream
• Stream is a process to read a data from 1 resource and
send a data to another location.
• Example :
– Read and write file at and to Harddisk
– Read and write text to console
– Read and write to network
• Stream has 2 type :
– Stream Byte (8bit): File for binary data
– Stream Character (16bit) : File for Unicode data
5. Java.io Hierarchy
• Package java.io was develop to make easy for
user to do an various type for input or output
process such as Objects, Strings and Bytes.
• It also design in order to receive input and
output from various source such as keyboard,
network and disk.
6. I/O Stream
• To READ, a program will open STREAM at a resource
(file, memory, socket) and READ an information in
sequential.
• And to WRITE, a program will send an information to a
destination. It will open a STREAM and it will WRITE an
information in sequential
• hhhhhhhhhhhhh
7. Reader and Writer
• Use for READ and WRITE text data
• It more easy then InputStream and
OutputStream
• For fast performance, use a buffering facility,
Example : BufferedReader.
8. Reader
• To READ a text by paragraph, use below
technique :
– File f = new Fine (“C:OOPMyText.txt”);
– FileReader fr = mew FileReader(f);
– BufferedReader fin = new BufferedReader(fr);
• FileReader is a lane that provide to read a File.
• BufferedReader wrap a FileReader in order to
make input process using buffering technique.
12. Reader
• After BufferedReader formed, String will be
taken with a readLine() method that use to
return a String value.
• To display a data it will use print() or println().
13. Writer
• Use to WRITE a text line by line use following
technique :
– File f = new File (“C:OOPMyText.txt”);
– FileWriter fw = new FileWriter(f);
– PrintWriter fin = new PrintWriter(fw);
• A file will be process to be FileWriter that is
needed for output.
• PrintWriter is needed in order to make program
can use a print() and println() method.
16. Stream Byte
• Actually stream byte divide by 2 class :
InputStream and OutputStream
• InputStream and OutStream is a higher level
in java.io package.
17. Stream Byte
• InputStream and OutStream is a class for
stream I/O that use to READ and WRITE a data
from and to file.
• For READ a file, we use : FileInputStream
• For WRITE a file, we use : FileOutputStream
19. How to use a byte stream?
INPUT STREAM OUTPUT STREAM
Create object that oriented with source
data.
Eg : FileInputStream
Create object that oriented with
destination data.
Eg : BufferedWriter
Read information from stream by using
object method.
Eg : read()
Write an information to stream by using
object method.
Eg : write()
When complete, close method will be
call.
When complete, closure method will be
call.