title: Error whilst using StringTokenizer on text file with multiple lines
body: <p>I'm trying to read a text file and split the words individually using string tokenizer utility in java.</p>
  
  <p>The text file looks like this;</p>
  
  <pre><code>a 2000
  
  4  
  b 3000  
  c 4000  
  d 5000
  </code></pre>
  
  <p>Now, what I'm trying to do is get each individual character from the text file and store it into an array list. I then try and print every element in the arraylist in the end.</p>
  
  <p>Here is my code;</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.FileReader;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.StringTokenizer;
  
  public static void main(String[] args) {
  
      String fileSpecified = args[0];
  
      fileSpecified = fileSpecified.concat(".txt");
      String line;
      System.out.println ("file Specified = " + fileSpecified);
  
      ArrayList &lt;String&gt; words = new ArrayList&lt;String&gt; ();
  
  
      try {
          FileReader fr = new FileReader (fileSpecified);
          BufferedReader br = new BufferedReader (fr);
          line = br.readLine();
  
          StringTokenizer token;
          while ((line  = br.readLine()) != null) {
              token = new StringTokenizer (line);
              words.add(token.nextToken());
          }
      } catch (IOException e) {
          System.out.println (e.getMessage());
      }
  
      for (int i = 0; i &lt; words.size(); i++) {
          System.out.println ("words = " + words.get(i));
      }
  
  
  
  }
  </code></pre>
  
  <p>The error message I get is this;</p>
  
  <pre><code>Exception in thread "main" java.util.NoSuchElementException   
                  at java.util.StringTokenizer.nextToken&lt;Unknown Source&gt;  
                  at getWords.main&lt;getWords.java:32&gt;  
  </code></pre>
  
  <p>Where 'getWords' is the name of my java file.</p>
  
  <p>Thankyou.</p>