0% found this document useful (0 votes)
2 views

Module 10 Study Guide

Uploaded by

202310943
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Module 10 Study Guide

Uploaded by

202310943
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Module 10 Study Guide

InputStream and OutputStream

Java I/O (Input and Output) is used to process the input and produce the output.
Java uses the concept of a stream to make I/O operation fast. The java.io package
contains all the classes required for input and output operations.
We can perform file handling in Java by Java I/O API.
A stream is a sequence of data. In Java, a stream is composed of bytes. It's called a
stream because it is like a stream of water that continues to flow.
In Java, 3 streams are created for us automatically. All these streams are attached with
the console.
1) System.out: standard output stream
2) System.in: standard input stream
3) System.err: standard error stream
OutputStream
Java application uses an output stream to write data to a destination; it may be a
file, an array, peripheral device or socket.

InputStream
Java application uses an input stream to read data from a source; it may be a file,
an array, peripheral device or socket.

OutputStream Class
Java OutputStream class is an abstract class. It is the superclass of all classes
representing an output stream of bytes. An output stream accepts output bytes
and sends them to some sink.

InputStream class is an abstract class. It is the superclass of all classes representing an


input stream of bytes.
Useful methods of InputStream

Java FileOutputStream is an output stream used for writing data to a file.


If you have to write primitive values into a file, use FileOutputStream class. You can
write byte-oriented as well as character-oriented data through FileOutputStream class.
But, for character-oriented data, it is preferred to use FileWriter than FileOutputStream.
FileOutputStream class declaration for Java.io.FileOutputStream class:

Java FileInputStream class obtains input bytes from a file. It is used for reading byte-
oriented data (streams of raw bytes) such as image data, audio, video etc. You can also
read character-stream data. But, for reading streams of characters, it is recommended
to use FileReader class.
FileInputStream class declaration for Java.io.FileInputStream class:

FileWriter and FileReader

Java FileWriter class is used to write character-oriented data to a file. It is character-


oriented class which is used for file handling in java.
Unlike FileOutputStream class, you don't need to convert string into byte array because
it provides method to write string directly.
Java.io.FileWriter

Java FileReader class is used to read data from the file. It returns data in byte format
like FileInputStream class.
It is character-oriented class which is used for file handling in java.
Java.io.FileReader

You might also like