Previous | Next | Trail Map | Learning the Java Language | The Nuts and Bolts of the Java Language

Running the countChars Method

The following main method for the Count class opens a Reader on a file named on the command line and then calls countChars with that Reader. You can use this application to run countChars.
import java.io.*;
public class Count {
    // ... countChars method omitted ...
    public static void main(String[] args) throws Exception
    {
        if (args.length >= 1)
            countChars(new FileReader(args[0]));
        else
            System.err.println("Usage: Count filename"); 
    }
}
The output of this program depends on what's in the file named on the command line. These platform-specific instructions show you how to run the application on a file named testing that contains the following ASCII text and displays the results:
Ich bin ein Berliner.
I am a jelly doughnut.
Now that you've seen the countChars method in action, the remainder of this lesson looks at the various components that make up the method and how they fit into the Java language.


Previous | Next | Trail Map | Learning the Java Language | The Nuts and Bolts of the Java Language