loader image
Skip to main content
If you continue browsing this website, you agree to our policies:
x
Completion requirements

This chapter discusses Java's FileReader and BufferedReader classes in detail. FileReader and BufferedReader classes are used together when reading data from an external file. The use of the BufferedReader class allows data to be buffered as it is read from a file before manipulating it. The readLine() method of the BufferedReader class reads a line of text from a character-oriented input stream, and puts it into a new String object.

5. Constructors


Answer:

Yes. All this object creation (and the garbage collector running in the background) takes processor time, but for most programs this is not noticeable.

Constructors


The constructor for BufferedReader looks like this:

BufferedReader( Reader in ) 

The constructor for FileReader looks like this:

FileReader( String fileName ) throws FileNotFoundException

The methods from BufferedReader which interest us are:

void close() throws IOException       // close the stream

int read() throws IOException // read a single character into an int

String readLine() throws IOException // read one line of characters into a String.

The read() method will be discussed later. (Both classes have other constructors and other methods which will not be discussed here).

Question 5:

What does the close() method do with an input stream?