title: Write a program to count the number of times that the character "a" appears anywhere in the file JavaIntro.txt.
body: <p>I am trying to figure out how to count all of the numbers into 1 counter this counts the number of 'a' from each line and displays each line I want to know how to count all of them onto one line.</p>
  
  <pre><code>import java.io.*;
  import java.util.Scanner;
  
  
  public class CountTheNumberOfAs {
      public static void main(String[] args)throws IOException
      {
  
          String fileName = "JavaIntro.txt";
          String line = "";
          Scanner scanner = new Scanner(new FileReader(fileName));
          try {
  
            while ( scanner.hasNextLine() ){
              line = scanner.nextLine();
              int counter = 0;
  
              for( int i=0; i&lt;line.length(); i++ ) {
                  if( line.charAt(i) == 'a' ) {
                      counter++; 
  
                  } 
  
  
              }
  
               System.out.println(counter);   
            }
          }
          finally {
  
            scanner.close();
  
  
      }}}
  </code></pre>