I'm trying to implement a user input interface for a board game. I'm trying to get user input one at a time and then writing it to a file (since I need to save the list of moves made by the user). What I have so far, works well (reading input and writing it to file), however, whenever the user wants to stop inputting, the program just stops working. I.E; when you press ctrl+c, the program just ends.
Here is what I have so far, the fileName variable has been declared outside the main function
public static void main(String[] args) throws IOException { BufferedReader inputReader = new BufferedReader (new InputStreamReader (System.in)); try { FileWriter outFile = new FileWriter (fileName); PrintWriter out = new PrintWriter (outFile); System.out.print ("Enter move: "); String line = inputReader.readLine(); while (line != null) { System.out.print ("Enter move: "); out.write(inputReader.readLine()); out.write(" "); } out.close(); } catch (IOException e) { System.out.println (e.getMessage()); } System.out.println ("Reached here"); } What I'm trying to do is whenever the user wants to stop inputting, I want to get to the print line where it says "Reached here". I want to do this because once outside of the loop, I can read the file and then split the input and maniplate it. I remember whilst programming in C, there used to be while (input != EOF); where whenever the user entered ctrl+d or ctrl+c, it stops whatever it is doing and then moves onto the next line of code. How can I do this in java?
Many thanks.