/*
	The program demonstrate a simple File Input that appends data
	In addition, it allows the user to create the name of file
	
* 
*/
import java.util.*; // Needed for Scanner class
import java.io.*;	// Needed for File input and output

public class FileAppend
{
	public static void main(String[] args)throws IOException 
	{
		Scanner key = new Scanner(System.in);
		
		// Asks the user for how many name will be enter
		
		System.out.println("How many names are you going to enter: ");
		int num = key.nextInt();
		
		// Ask the user for the name of the file
		
		System.out.println("Enter the name of the file: ");
		String filename = key.next();
		
		// Opens the file or create a file if it doesn't exist
		
		FileWriter fw = new FileWriter(filename, true);
		PrintWriter pw = new PrintWriter(fw);
		
		for(int i=0; i<num; i++)
		{
			// Gets the name from the user
			
			System.out.println("Enter a name: ");
			String name = key.next();
			
			// Writes the name into the file
			pw.println(name);
		}
		
		/*
			Closes the file
			A step that always need to remember to do
			
		*
		*/
		pw.close();
	}
}