/**
  OpenFileTest.java
  a program that tests OpenFile.java
  @version 1.0
  @author cosc 2325 class
*/
import java.util.*;
import java.io.*;
public class OpenFileTest 
{
  public static void main(String args[]) {
    Scanner in = null;
    PrintWriter out = null;
    Scanner kbd = new Scanner(System.in);
    String fileName;
    String answer;
    do {
      System.out.print("enter name of file for input: ");
      fileName = kbd.nextLine();
      in = OpenFile.openInputFile(fileName);
      if(in != null) {
        System.out.println("Here is the firstline on the file: " +
                         in.nextLine());
        in.close();
      }
      System.out.println("*****\n" +
                         "Now testing creating a PrintWriter");
      System.out.print("Enter name of file to open for writing: ");
      fileName = kbd.nextLine();
      out = OpenFile.openOutputFile(fileName);
      if(out != null) {
        System.out.println("Enter text to write to file: ");
        String line = kbd.nextLine();
        System.out.println("Now printing:\n " + line + "\n to output file.");
        out.println(line);
        out.close();
      }
      System.out.print("Repeat? y or n: ");
      answer = kbd.nextLine();
    } while(answer.toLowerCase().equals("y"));
            
  } // end of main
} // end of OpenFileTest class
