System Object Model
Exceptions - Quiz
Throwing Exceptions - Quiz.
Catching Exceptions Baseball
Common Java Exceptions
Using Join for Threads
Starting JavaThread - Quiz
Coordinating Java Threads - Quiz
Thread States -Quiz
Java Input Output
Java IO Package
JavaClass InputOutput Review
Java IO Quiz
Reading File Java - Exercise
Read from a file
For this exercise, write a character-mode, stand-alone program that reads from a file and counts and displays the number of characters in this file. The file to read should be passed to the program as a command-line argument. (In other words, the file to read will be a string in
in your program's
To create a stream that you can use to read from a file, you can create an instance of
. To create this instance, pass its constructor a string instance representing the file to read.
To read a byte, you can use an instance method defined by
returns the value -1, it has reached the end of the file. So, you can keep on looping, reading, and counting until you get -1.
Try running the file on itself. In addition, use the
block where appropriate to handle any
Place your code in the text area below when you are satisfied that it is working correclty.