title: How to output a list of numbers from a file on the same line in java
body: <p>What I have so far:</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  import javax.swing.JOptionPane;
  
  public class FileEg
  {
    public static void main (String [] args) throws Exception
    { int sum = 0, ctr = 0;
      double next;
      String line;
      String filename = "eg.txt";
      StringTokenizer st;
      PrintWriter outFile = new PrintWriter("eg.out");
      outFile.println("Output File");
      try
      { Scanner inFile = new Scanner(new FileReader (filename));
        while (inFile.hasNext())
        { line = inFile.nextLine();
          st = new StringTokenizer(line);
          while (st.hasMoreTokens())
          { next = Double.parseDouble(st.nextToken());
            sum += next;
            ctr++;
            outFile.println(next);          
          }
      }     
      outFile.println("number of integers read is " + ctr);
      outFile.println("average is " + sum/(double)ctr);
      outFile.close();
      }     //end of try
     catch(FileNotFoundException e)
     { System.out.println ("The file eg.dat was not found.");
     }
     catch(NumberFormatException e)
     { System.out.println ("sorry - number format error");
       System.out.println(e);
     }
    }
  }
  </code></pre>
  
  <hr>
  
  <p>I need to get the output at least 2 different lines and with more than on number on one line. so far it comes out like this in the output file.</p>
  
  <p>Output File</p>
  
  <p>2.5</p>
  
  <p>6.2</p>
  
  <p>9.3</p>
  
  <p>1.2</p>
  
  <p>3.5</p>
  
  <p>6.1</p>
  
  <p>5.0</p>
  
  <p>8.0</p>
  
  <p>4.0</p>
  
  <p>8.0</p>
  
  <p>number of integers read is 10
  average is 5.2</p>