File Handling
File Handling
FileInputStream:
● It is a predefined class present in the io package.
● The primary purpose of this class is to read or retrieve the data from a particular
file by opening the file in read mode.
Constructors:
● FileInputStream(String)
Methods:
● Int read()
● int read(byte[])
● void close()
BufferedOutputStream:
● It is a predefined class present in the io package.
● Using this class, we can transfer the data with a buffer facility.
● A buffer is a temporary memory space, while transferring the data, it will also be
stored in the buffer.
Constructors:
● BufferedOutputStream(OutputStream)
Methods:
● void write(int)
● void write(byte[])
● Void flush()
BufferedInputStream:
● It is a predefined class present in the io package.
● The primary purpose of this class is to read or retrieve the data and we can get
the data from the buffer.
Constructors:
● BufferedInputStream(InputStream)
Methods:
● int read()
● int read(byte[])
● void flush()
● void close()
SequenceInputStream:
● It is a predefined class present in the io package.
● The primary purpose of this class is to read or retrieve data from multiple files at
a time.
Constructors:
● SequenceInputStream(InputStream, InputStream)
● SequenceInputStream(Enumeration)
Methods:
● int read()
● int read(byte[])
● void close()
ByteArrayOutputStream:
● It is a predefined class present in the io package.
● The primary purpose of this class is to write or transfer common data or similar
data into multiple files
● It will transfer the data in the form of an array of bytes.
Constructors:
● ByteArrayOutputStream()
Methods:
● void write(int)
● void write(byte[])
● void writeTo(OutputStream)
● void close()
File Writer:
● It is a predefined class present in the io package.
● The main purpose of this class is to write a stream of characters into a file, here
we can send the String values directly without converting them into bytes. It is an
extended class of the Writer class.
Constructors:
● FileWriter(String)
Methods:
● void write(String)
● void write(char)
● void write(char[])
● void flush()
● void close()
File Reader:
● It is a predefined class present in the io package.
● The main purpose of this class is to read the Stream of Characters.
Constructors:
● FileReader(String)
Methods:
● Int read()
● void close()
Buffered Writer:
● It is a predefined class present in the io package.
● The functionality of this class is to provide a buffered system for efficient writing
of data.
Constructors:
● BufferedWriter(Writer)
Methods:
● void write(int)
● void write(String)
● void write(char[])
● void write(byte[])
● void close()
Buffered Reader:
● It is a predefined class present in the io package.
● It will provide buffer functionality for the Reader class.
Constructors:
● BufferedReader(Reader)
Methods:
● Int read()
● String readLine()
● byte[] read(byte[])
● void close()
Functional Interface:
An Interface which has only one method is called a Functional Interface
Marker Interface:
An Interface that does not have any properties in it is called a Marker Interface.
Serialization:
The process of transferring or sending n number of bytes of data from a Java
Application to an external file in terms of an object is called Serialization.
De-Serialization:
It is the process of reading or retrieving n number of bytes of data from a text file
to a Java Application.