FileReader and BufferedReader

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

FileReader and BufferedReader

FileReader and BufferedReader

FileReader is used for input of character data from a disk file. The input file can be an ordinary ASCII, one byte per character text file. A Reader stream automatically translates the characters from the disk file format into the internal char format. The characters in the input file might be from other alphabets supported by the UTF format, in which case there will be up to four bytes per character. In this case, also, characters from the file are translated into char format.

As with output, it is good practice to use a buffer to improve efficiency. Use BufferedReader for this.

BufferedReader stdin = 
    new BufferedReader(new InputStreamReader( System.in ));

These lines create a BufferedReader, but connect it to an input stream from the keyboard, not to a file.

QUESTION 3:

(Memory test:) What method reads a line of characters from a BufferedReader?