ShortWords.java

import java.awt.*;
import java.io.*;
import java.awt.event.*;

// A program to count the number of short words in a 
// dictionary file
public class ShortWords {

    
    public static void main(String[] args) {
        
        BufferedReader words;        // stream of dictionary words
        String curWord;                        // the current word
        
        int count = 0;                        // count of short words seen
        
        try {
            // create a stream to access dictionary file
            words = new BufferedReader(new FileReader(args[0]));
                                
            // get the first line of the file
            curWord = words.readLine();
            while ( curWord != null ) {
                if ( curWord.length() == 4 ) {
                    count++;
                    System.out.println(curWord);
                }
                
                // get the next line from the file
                curWord = words.readLine();
            }
                        
            System.out.println("Total = " + count );
            words.close();

        } catch ( IOException e) {
            System.out.println("Error reading dictionary file");
        }
    }
}