title: count number of lines, tokenizing
body: <p>I would like to count the number of lines in a file, splitting it into tokens. I cannot seem to get my code working, could someone please offer advice. Thanks in advance</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class kup
  {
      public static void main(String args[]) throws Exception
      {
          FileReader fileInput = new FileReader("C:\\save\\input.txt");
          BufferedReader readInput = new BufferedReader(fileInput);
  
          FileWriter fileOutput = new FileWriter("C:\\save\\output.txt");
          PrintWriter outFile = new PrintWriter(fileOutput);
  
          Scanner scanLine = new Scanner(readInput);
          String textInput = scanLine.nextLine();
          StringTokenizer stringtokenizer = new StringTokenizer(textInput);
  
          int tokenCount = stringtokenizer.countTokens();
          int lineCount = 0;
  
          while(scanLine.hasNextLine())
          {
              while(stringtokenizer.hasMoreTokens())
              {
                  String string = stringtokenizer.nextToken();
                  outFile.println(string);
              }
                  lineCount++;
          }
  
          outFile.println("Number of words: " +tokenCount);
          outFile.println("Number of lines: " +lineCount);
  
          readInput.close();
          outFile.close();
      }
  
  }
  </code></pre>