title: DataInputStream for input text files?
body: <p>I am learning to read and write in Java and am stuck with a simple exercise. The program reads from 2 txt files that each contain numbers in rows. It writes to an output file the result of the multiplication of each row of numbers. eg. file 1 row 1 : 10, file 2 row 1: 2 , the program should write 20 to the output file. My code seems to have something missing somewhere. The output file is created but nothing is written to it. Any ideas?</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  class ReadWriteData
  {
      public static void main(String[] args) throws Exception 
      {
  
          //create ouput file
          PrintWriter output = new PrintWriter("output2.txt");
  
          DataInputStream file1 = new DataInputStream(new FileInputStream(args[0]));
          DataInputStream file2 = new DataInputStream(new FileInputStream(args[1]));  
  
          try
          {
  
          // read data from file
          while (true)
          {
              double number1 = file1.readDouble();
              double number2 = file2.readDouble();
              double result = number1 * number2 ;
              output.println(result);
  
          }
  
  
          }
  
          catch (IOException e)
          {
              System.err.println("Error");
              System.exit(1);
          }
  
          output.close() ;
  
      }
  }
  </code></pre>