import java.util.Scanner;
import java.io.*;

public class Exam3v2 {
	public static void main(String[] args) {
		Scanner kb = new Scanner(System.in);
		while(true) {
			printMenu();
			String option = kb.nextLine();
			switch(option) {
				case "1":
					copyFile();
					break;
				case "2":
					return;
				default:
					System.out.println("Invalid choice");
			}
		}

	}

	static void printMenu() {
		System.out.println("1) Copy file");
		System.out.println("2) Exit");
		System.out.print("Choose a menu option: ");
	}

	static void copyFile() {
		Scanner kb = new Scanner(System.in);
		System.out.print("Enter existing file name: ");
		String sourceFileName = kb.nextLine();
		System.out.print("Enter new file name: ");
		String destinationFileName = kb.nextLine();

		Scanner fin = null;
		PrintWriter pw = null;

		try {
			File f = new File(sourceFileName);
			fin = new Scanner(f);
			f = new File(destinationFileName);
			pw = new PrintWriter(f);
		}
		catch(FileNotFoundException e) {
			System.out.println("File not found");
			return;
		}

		while(fin.hasNext()) {
			String line = fin.nextLine();
			pw.println(line);
		}
		
		pw.close();
		fin.close();
	}

}
