Constructors

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:

Easy, just do this:

   String fileName = args[0] ;

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 methods which will not be discussed here).

QUESTION 5:

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