java.io dilemma

filereader, inputstreamreader, java

Solution

The method in `InputStreamReader` provides the implementation for the abstract method in `Reader`. `FileReader` doesn't override that method any further; it just inherits the implementation from `InputStreamReader`.

Note that there are four signatures for read:

public int read()
public int read(char[] cbuf, int offset, int length)
public int read(char[] cbuf)
public int read(CharBuffer target)

`InputStreamReader` only overrides the first two of these. Perhaps that's what was confusing you?

Problem

The classes java.io.Reader and java.io.InputStreamReader both have read methods with the exact same signature ``` public int read(char[] charbuf, int offset, int length) throws IOException ``` Now according to the java documentation the class java.io.FileReader inherits both these read() methods from both the above-mentioned classes. Now as FileReader extends InputStreamReader which further extends Reader ``` (Reader <-- Inputstreamreader <-- FileReader) ``` and the read() has same signature in both classes, shouldn't it have been that InputStreamReader overrode the read() from Reader and FileReader inherited that over-ridden method?? Or am i missing something here?? Also the two read()s inherited by FileReader have slightly different functionality (something about one blocks while waiting for input while the other doesn't).

Original source