Java FileReader Class

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.

Constructors of FileWriter class

  1. FileWriter(String file)

    It gets filename in string. It opens the given file in read mode. If file doesn't exist, it throws FileNotFoundException.

  2. FileWriter(File file)

    It gets filename in file instance. It opens the given file in read mode. If file doesn't exist, it throws FileNotFoundException.


Methods of FileReader class

  1. int read()

    It is used to return a character in ASCII form. It returns -1 at the end of file.

  2. void close()

    It is used to write the char into FileWriter.

  3. void write(char[] c)

    It is used to close the FileReader class.

Java FileReader Example

In this example, we are reading the data from the text file testout.txt using Java FileReader class.

Flash Soon


Output:



Advertisement

Copyright ©2017 Design& develop