Java FilterReader.read()
Syntax
FilterReader.read() has the following syntax.
public int read() throws IOException
Example
In the following code shows how to use FilterReader.read() method.
//from w ww .j a v a 2 s .c om
import java.io.FilterReader;
import java.io.Reader;
import java.io.StringReader;
public class Main {
public static void main(String[] args) throws Exception {
int i = 0;
char c;
// create new reader
Reader r = new StringReader("ABCDEF");
// create new filter reader
FilterReader fr = new FilterReader(r) {
};
// read till the end of the stream
while ((i = fr.read()) != -1) {
// converts integer to character
c = (char) i;
// print
System.out.println("Character read: " + c);
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »