/* TextFileOutput.java        Authors: Koffman & Wolz
 * Demonstrates writing to an output stream.
 * Uses PrintWriter and FileWriter.
 */
import java.io.*;

public class TextFileOutput {

   // postcondition: Writes two lines to file myOut.txt.
   public static void main(String[] args) {
      try {
        FileWriter outStream = new FileWriter("myOut.txt");
        PrintWriter outs = new PrintWriter(outStream);

        // Write 2 lines to the output file.
        outs.println("Age is " + (int) (Math.random() * 100));
        outs.println("Name is " + "Sally");
        outs.println("Age is " + (int) (Math.random() * 100));
        outs.println("Name is " + "Sam");

        // Write a console message and close the output file. 
        System.out.println("File written");
        outs.close();
      }
      catch (IOException e) {
        System.out.println("i/o error " + e.getMessage());
      } 
   }
}

