0% found this document useful (0 votes)
22 views17 pages

Java

Uploaded by

shreya.ramya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views17 pages

Java

Uploaded by

shreya.ramya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

I/O STREAMS IN JAVA

TEAM – 3
SARATHI
SHREYA B
SANDHIYA T
RAM SUNDAR M
SIVA SURYA V S 310622104140
SIVASHANKAR M 310622104142
CONTENT
• Introduction to I/O streams
• Byte stream
• Character stream
• Buffered stream
• File I/O operations
• Serializing and deserializing
Stream Output stream
• A stream is a sequence of data. In Java,
a stream is composed of bytes.
• In Java, 3 streams are created for us
automatically. All these streams are
attached with the console.
• 1) System.out: standard output stream
Input stream
• 2) System.in: standard input stream
• 3) System.err: standard error stream
I/O streams in java
• In Java, I/O (Input/Output) streams provide a way to handle
input and output operations.
• Two types of streams
Input and output stream : represent the flow of data into and out of
a program
Byte Stream
• ByteStream classes are used to read bytes from the input stream and write
bytes to the output stream.
• ByteStream classes read/write the data of 8-bits.
• The ByteStream classes are divided into two types of classes, i.e., InputStream
and OutputStream. These classes are abstract and the super classes of all the
Input/Output stream classes.

Examples of ByteStream Classes:


• FileInputStream and FileOutputStream: Read from and write to files
• ByteArrayInputStream and ByteArrayOutputStream: Operate on byte arrays
in memory.
• DataInputStream and DataOutputStream: Read and write primitive data
types.
OUTPUT :
Character Stream
• Character streams are used to handle text-based data
Types of Character Stream Classes:
• Reader: Abstract class for reading characters from different sources.
• Writer: Abstract class for writing characters to different destinations.

Examples of Character Stream Classes:


• FileReader and FileWriter: Read from and write to text files, respectively.
• StringReader and StringWriter: Read from and write to strings.
• BufferedReader and BufferedWriter: Provide buffering capabilities for
improved performance
OUTPUT :
Buffered stream
Buffered input streams read data from a memory area known as a buffer;
Similarly, buffered output streams write data to a buffer.

There are four buffered stream :


• BufferedInputStream and BufferedOutputStream - create buffered byte
streams
• BufferedReader and BufferedWriter - create buffered character streams
OUTPUT:
File I/O operations
1.Writing to a File:
Java provides FileWriter and BufferedWriter classes for writing data to
files.
2.Reading from a File:
FileReader and BufferedReader classes facilitate reading data from files
in Java.
3.Exception Handling:
File I/O operations in Java may encounter IOExceptions due to various
reasons like file not found or permission issues
Exception handling with file I/O
• Exception handling is crucial when performing file I/O operations in
Java to handle potential errors gracefully.
• Common exceptions include FileNotFoundException, IOException, and
SecurityException
• Use try-catch blocks to surround file I/O operations that may throw
exceptions.
• Each catch block should handle a specific type of exception, providing
meaningful error messages or appropriate error recovery actions.
OUTPUT :

You might also like