In this section we will learn about the FilterReader class in Java.
In this section we will learn about the FilterReader class in Java.In this section we will learn about the FilterReader class in Java.
java.io.FilterReader is an abstract class provides the facility to read filtered character streams. Instance of this class can not be created directly. Subclasses of FilterReader may override methods of this class and may allow extra methods and fields.
Constructor of FilterReader
FilterReader(Reader in) | This constructor creates a new FilterReader. Syntax : protected FilterReader(Reader in) |
Methods in FilterReader
Example
A simple example of FilterReader is being given here. In this example I have created a Java class named JavaFilterReaderExample.java. In this class I have used the FileReader class which provides a file as data source. Further in the core of this class tried to read the characters from the file. To read the the characters used read() method.
Source Code
JavaFilterReaderExample.java
import java.io.FilterReader; import java.io.FileReader; import java.io.Reader; import java.io.BufferedReader; import java.io.IOException; class JavaFilterReaderExample extends FilterReader { public JavaFilterReaderExample(Reader rdr) { super(rdr); } public static void main(String[] args) { FileReader fr = null; try { fr = new FileReader("file.txt"); int i; while((i= fr.read()) != -1) { System.out.print((char)i); } } catch(IOException e) { System.out.println(e); } finally { if(fr != null) { try { fr.close(); } catch(Exception e) { System.out.println(e); } } }// end finally }// end main }// end class
Output
When you will execute the above code then the output will be as follows :
Ads