import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
public class FileWriteDemo1 {
   public static void main (String[] args)
            throws FileNotFoundException {
      File f = new File("fileout1.txt");
      
      /* Scanner */
      PrintStream fout = new PrintStream(f);
      PrintStream sout = new PrintStream(System.out);
      /* Storing away */
      for (int i = 0; i < 2; i++) {
         PrintStream xout;
         if (i==0) xout = fout;
         else if (i==1) xout = sout;
         else xout = null;
         xout.println("Students: this is line one");
      
         xout.printf("Line = %d  \n", 2);
      
         xout.println("Another very nice line saved for posterity!");
      }
      
      /*
      // Reading back 
      Scanner fin = new Scanner(f);
      while (fin.hasNextLine()) {
         System.out.println(fin.nextLine());
      }
      */
   
   }
}