Java Input/Output  «Prev  Next»

Reading from File - Exercise

Objective: Write an application that counts the number of characters in a file and then displays the count.

Instructions

Write an application called ReadFile that counts the number of characters in a file and then displays the count. The name of the file will be specified by the user as a command-line argument.
There are a number of valid approaches to writing this application. Perhaps the simplest solution is to create an instance of FileInputStream (passing the name of the file in the constructor) and then counting the number of times you can invoke read() until the end of file is reached. The read() method returns -1 to indicate the end of a file. You are welcome to use this approach or to try another.

Exercise scoring

The full credit for this exercise is 5 points. To receive full credit, you will need to successfully create the source code for the application. You will then submit your source code.

What to submit

In the text box below, cut and paste the source code for ReadFile. Click, the Submit button to submit the code.