Count the words in a file by symbol
<p>I need to count all the words in a file, which begin and end with the letter "A". While I was able to count all the words in a file. Here is the code ...</p>

<pre><code>public class task_1 {

public static int i;

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws IOException {
    Scanner sc = new Scanner (System.in);
    String name = sc.nextLine();
    sc.close();
    FileReader fr2 = new FileReader(name);
    BufferedReader r = new BufferedReader(fr2);

    String s=r.readLine();

    int n=0;
    while(s!=null) {
        System.out.println(s);
        String [] words = s.split(" ");
        n += words.length;
        for(String str : words)
        {
            if(str.length()==0) n--;
        }
        s=r.readLine();
    }
    fr2.close();
    System.out.println(n);                                                          
    }
}
</code></pre>
