title: Java program to count lines, char, and words from a text file
body: <p>My output for the number of words and char keeps giving me zero. If anyone could help me find the
  error in my code that would be great. The code enclosed by the stars is the code given by our teacher
  and we are required to put this in our program. </p>
  
  <p>Thank you! </p>
  
  <p>** Our teacher told us not to use the buffered method. Also if I changes the lineNum method would it still override other methods? 
   Part of the assignment is to use at least two methods in our program****</p>
  
  <p>** I edited my code based on everyones advice** It is now printing the correct numbers! How can I implement my two methods within this? A suggestion was that I use the for loop for the wordCount method. 
  <strong>I also need help with counting number of paragraphs</strong>
  A good starting point?</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class WordStats1 {
  
  public static void main(String[] args) {
      try {
  
          Scanner input = new Scanner(new FileReader("data.txt"));
          //int totalLines = lineNum(input);
          //int wordCount = wordCount(input); 
          //int countChar = countChar(input);
  
  
          PrintWriter output = new PrintWriter(new FileOutputStream(
                  "newfile.txt"));
  
          int lineNum = 0;
          int wordCount = 1;
          int charCount = 0; 
  
          while (input.hasNextLine()) {
              String line;
              line = input.nextLine();
  
              //output.println(lineNum + ": " + line);
  
              lineNum++;
  
              String str [] = line.split((" "));
                for ( int i = 0; i &lt;str.length ; i ++) {
                  if (str [i].length() &gt; 0) {
                    wordCount ++; 
                  }
                }
                charCount += (line.length());
  
          }
  
          System.out.println(lineNum);
          System.out.println(wordCount); 
          System.out.println(charCount); 
          input.close();
          output.close();
  
          System.out.print("File written.");
  
      }
  
      catch (FileNotFoundException e) {
          System.out.println("There was an error opening one of the files.");
      }
  </code></pre>
  
  <p>}
  }</p>