/** lab1
 * @author Flavien HAAS
 * @version 1.0
 * october, 2020
 * Maynooth University
 */

import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


public class lab1 {

  public static void main(String args[]) throws IOException{

    String nameinputfile;
    String nameoutputfile;
    BufferedReader sometext;
    File inputfile;
    File outputfile;
    FileReader filereader;
    BufferedReader bufferedreader;
    FileWriter filewriter;
    String onelinecontent;

    //acquire input file name
    System.out.println("Please enter input file :");
    sometext = new BufferedReader (new InputStreamReader(System.in));
    nameinputfile = sometext.readLine();

    //acquire output file name
    System.out.println("Please enter output file :");
    sometext = new BufferedReader (new InputStreamReader(System.in));
    nameoutputfile = sometext.readLine();

    inputfile = new File(nameinputfile);
    outputfile = new File(nameoutputfile);

    //tests to see if files exists or not
    if (!inputfile.exists()){
      System.out.println("the input file name given does not exists");
      System.exit(0);
    }

    if (outputfile.exists()){
      System.out.println("the output file already exists");
      System.exit(0);
    }

    //copy the input file content to the the output file
    filereader = new FileReader(nameinputfile);
		bufferedreader = new BufferedReader(filereader);
		filewriter = new FileWriter(nameoutputfile, true);

		while ((onelinecontent = bufferedreader.readLine()) != null) { // read a line
      filewriter.write(onelinecontent); // write to output file
			filewriter.flush();
		}

    bufferedreader.close();
		filewriter.close();

    //write completion message to screen
    System.out.println("the content from the input file has been copied to the output file");

  }
}
