Thursday, 1 September 2016

File Handling in Java

                File Handling in Java

All classes required for Java I/O (Input/Ouput) will resides in java.io package .

A stream is considered to be a sequence of data and it is composed of bytes and there are two kinds of streams
InputStream : The input stream is used to read the data from a source.

OutpurSteam : This is used to write the data to a destination.

InputStream class :
This is a super class of all the classes which implements input stream of bytes. It is an abstract class

Commonly used methods:

1) public abstract int read()throws IOException : It reads the next byte of data from the input stream.It returns -1 at the end of file.

2) public int available()throws IOException: It returns an estimate of the number of bytes that can be read from the current input stream.

3) public void close()throws IOException:It is used to close the current input stream.

OutputStream class :

 This is a super class of all the classes which implements ouput stream of bytes. It is an abstract class.

Commonly used methods:

1) public void write(int)throws IOException: It is used to write a byte to the current output stream.

2) public void write(byte[])throws IOException:It is used to write an array of byte to the current output stream.

3) public void flush()throws IOException:It flushes the current output stream.

4) public void close()throws IOException:It is used to close the current output stream.

2 comments:

  1. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.
    Selenium Training in Chennai

    ReplyDelete
  2. Is there a way I can transfer all my Word Press posts into it? Any help would be appreciated.
    safety course in chennai

    ReplyDelete