title: Read in number file and calculate average in java
body: <p>I have a txtfile called "averages" that looks like:</p>
  
  <pre><code>1 4 5 3 -1
  2 8 9 3 2 -1
  4 8 15 16 23 42 -1
  3 -1
  </code></pre>
  
  <p>I want to be able to read in each line and calculate the average of each line whenever a "-1" is reached. I have written the code to read in the file and print it to the command line, I'm just having trouble finding the averages of each line. Any help would be greatly appreciated. Thanks!</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class Test {
  
      public static void main(String[] args) {
          BufferedReader reader = null;
  
          try {
              String currentLine;
  
              reader = new BufferedReader(new FileReader("averages.txt"));
              while  ((currentLine = reader.readLine()) != null) {
                  System.out.println(currentLine);
              }
          } catch (IOException err) {
              err.printStackTrace();
          } finally {
              try {
                  if (reader != null)reader.close();
              } catch (IOException err) {
                  err.printStackTrace();
              }
          }
  
  }
  }
  </code></pre>